How to match exactly one item in an array

(AlloVince) #1

Hi guys

I have a question when matching a field with array.

Here is my data:


 "names": ["foo-123-sth-more", "bar-456-sth-more"]


 "names": ["foo-456-sth-more", "bar-123-sth-more"]

My query is

    "query": {
        "match" : {
            "names" : {
                "query" : "foo 456",
                "operator" : "and"

Both item1 and item2 will matched, but the expected result is only item2 match, every element in array should be consider as an independent text to handle.

Is there any one could tell me how to handle this case? thank you.

(Jaspreet Singh) #2

You should use nested datatypes. It is just the way arrays are indexed that shows the behaviour are you noticing.
Check this out -

(system) closed #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.