pymilvus search embeddings by JSON

26 Views Asked by At

I'm using pymilvus 2.2.13. I have a JSON field in my collection: metadata: {"firld_a": "x", "list_field": ["A", "B", "C"]} I want to get all the embeddings that have A in their list field, I tried to use json_contains like the following example:

self.collection.query(
     expr=f'json_contains(metadata["list_field"],"A")', 
     output_fields=['metadata']
)

and got a milvus error, how can I get the requested result?

1

There are 1 best solutions below

1
WenChia T'u On

You should use json_contains_any instead of json_contains. Note that json_contains regards the value of each key as a whole, while json_contains_any checks the elements.

For details, refer to Advanced Operators here.