Search for empty value in metadata field AND specific value in another metadata field

Options
scotts0rensen
scotts0rensen Member Posts: 4
edited March 2023 in Developer APIs

I can search for an empty value in a metadata field with this expression:

-metadata=client_award_level

I can search for a value in a metadata field with this expression:

metadata.material_number="49738066"

But I get an error when I try to combine them with 'AND'

-metadata=client_award_level AND metadata.material_number="49738066"

com.cloudinary.api.exceptions.BadRequest: Query Error (at position 33) '-metadata=client_award_level AND ➥➥➥ metadata.material_number="49738066"'

How can I do this? I'm using the Java SDK which just passes the above expression to the API.

Best Answer

  • Vdeub
    Vdeub Member, Cloudinary Staff Posts: 53
    Answer ✓
    Options

    Hi Scott,

    You will need to put the negation as the last component of your expression i.e this will work:

    metadata.material_number="49738066" AND -metadata=client_award_level
    

    Hope that helps.

    Best,

    Loic

Answers

  • scotts0rensen
    scotts0rensen Member Posts: 4
    Options

    From trial and error I discovered that putting parenthesis around the metadata negation also works. This is a better solution in our situation than to put them all at the end of the expression.

    (-metadata=client_award_level) AND metadata.material_number="49738066"

  • tia
    tia Member, Cloudinary Staff Posts: 24
    Options

    Hi Scott,

    Thanks for sharing the solution you found. If you have any questions, just let us know 😊

    Kind regards,

    Tia