Skip to main content

Search Images using custom metadata attribute with multiple values for same key

Comments

11 comments

  • Shirly Manor

    Hi Roopesh,

    We announced our new structure metadata that might work the best for you to organize the data and then search for it in the future.

    You can read about it here:

    https://cloudinary.com/documentation/admin_api?query=structure%20metadata&c_query=Metadata%20fields%20%E2%80%BA%20Generic%20structure%20of%20a%20metadata%20field#metadata_fields

    Please note that if you want to try this feature we will need to set it on your account. you can do it by open a support request at support@cloudinary.com with your cloud name.

    Hope that helps,

    0
  • Roopesh gangwar

    Hi Shirly,

     

    My ask is still not answered in this document. I need to know if cloudinary recommend to capture multiple values for same key ? and how to perform search using one value from multiple values

    0
  • Shirly Manor

    It depends on your use-case. You can use `set` or `enum` as your type of metadata (we will need to turn on structure metadata for you).

    If you would like please open a support ticket to discuss your use case. 

    0
  • Roopesh gangwar

    Hi Shirly,

     

    My request is more of reading data from another application which is integrated with cloudinary. . Please refer to below scenario. For each image we have metadata attributes like Brand, Product-Family. Now for each metadata we are capturing multiple values for e.g. Brand = ABC;BCD;CB as refer in screenshot. Now I am using search api using context and I am trying to pass brand value = CB to get search result. But I am not get any response. I have to pass entire string of "ABC;BCD;CB" to get response.

     

    So I wanted to understand if we cannot capture multiple values for same metadata like Brand shown in this example and how I should perform search so that I can get output with Image details.

     

     

    0
  • Stephen Doyle

    Hi Roopesh,

    You should be able to search for a supplier name using your example above, with a search expression like this:

    context.Brand=BCD

    However, if the search term is very short you may not get good results, so BCD in this case may be too short.

     tried it in my own account with some longer values and it worked correctly when I had Brand set to "abcdef;bobco;brandco" - a search API expression of "context.Brand:bobco" finds the file correctly.

    Another possible option is to store the metadata fields you need to search most often as tags, for example, adding three tags like "Brand:ABC" "Brand:BCD", "Brand"CB"; this would give you other benefits like being able to request a JSON list of all images for brand ABC: https://cloudinary.com/documentation/advanced_url_delivery_options#client_side_resources

    Please let me know if  that helps,

    Regards,
    Stephen

     

    0
  • Roopesh gangwar

    Hi Stephen,

     

    The recommended solution worked, But I am facing another issue which is more related to incremental.

     

    Scenario: Business users are updating custom metadata every day for the images. But via API we are not seeing any changes on created_at or updated_at dates. Can you please let me know if there is any way to identify if there is change in the image record when someone updates metadata via API

     

    Thanks for help

    0
  • Aditi Madan

    Hi Roopesh,

    You can add notification URL in your upload setting. Then you can see the response at your notification URL. For example:

    {"notification_type":"resource_context_changed","source":"api","resources":{"my-public-id:{"added":[{"name":"key1","value":"mykey1"}],"removed":[],"updated":[]}}}
    

    If you are using the API then you can pass the notification_url param and that should send the response to the webhook.

    Thanks,

    Aditi

    0
  • Roopesh gangwar

    Hi Aditi,

     

    Not sure you understand my problem statement, Because your response doesn't relate to my problem. Let me explain by problem

     

    Scenario: I as business users.. decided to update custom metadata attribute to update image metadata … I make changes and close the image..

     

    Now when i try to check changes .. I am not able to track update via api .. which attribute I shud consider for identifying change in metadata .. via API

    0
  • Stephen Doyle

    Hi Roopesh,

    The `created_at` and `updated_at` values refer to the asset itself and aren't updated when the metadata is changed.

    If you'd like know when a business user changes some of the metadata, the option Aditi recommended is the best method for this, because we'll send your notification URL a request indicating the image which was changed and which values were added immediately after the change is made, so you don't need to poll or query the API periodically to see what has changed.

    For example, using the same file I used before if I configure a notification URL for my account and then add another value to the 'Brand' key in the image's context, my notification URL receives a request with this data:

    {
      "notification_type": "resource_context_changed",
      "source": "api",
      "resources": {
        "kitten_wide": {
          "added": [],
          "removed": [],
          "updated": [
            {
              "name": "Brand",
              "value": "ABCDEF;GHIJKL",
              "previous_value": "ABCDEF"
            }
          ],
          "resource_type": "image",
          "type": "upload"
        }
      }
    }

     

    And when I add a tag, the request looks like this:

     
    {
      "notification_type": "resource_context_changed",
      "source": "api",
      "resources": {
        "kitten_wide": {
          "added": [],
          "removed": [],
          "updated": [
            {
              "name": "Brand",
              "value": "ABCDEF;GHIJKL",
              "previous_value": "ABCDEF"
            }
          ],
          "resource_type": "image",
          "type": "upload"
        }
      }
    }

     

    This would notify you immediately about all changes, so you don't need to query via the API

    Regards,

    Stephen

    0
  • Roopesh gangwar

    Thanks Stephen,

     

    Quick question:

    Is custom metadata part of upload response which is sent to notification URL ?

    Also where in console we can add notification url. Can you please provide some steps to make this change ?

     

    Thanks,

    Roopeh

    0
  • Aditi Madan

    Hi Roopeh,

    Yes, the custom metadata is part of the upload response.

    You can add the notification URL here: https://cloudinary.com/console/settings/upload or if you are using an upload preset then there is an option to add the notification_url in the preset.

    Regards,

    Aditi

    0

Post is closed for comments.