0

I have a document indexed in my elastic search like:

{
   ...
   purchase:{
     zones: ["FR", "GB"]
     ...
   }
   ...
}

I use this kind of query to find for example document with puchase's zone to GB

{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "term": {
                    "purchase.zones": "GB"
                }
            }
        }
    }
}

But with it i get no results... I would like to perform a query like in php in_array("GB", purchase.zones).

Any help would be very helpful.

1 Answer 1

1

If your "purchase" field is nested type then you have to use nested query to access the "zones".

{
    "nested" : {
        "path" : "obj1",
        "score_mode" : "avg",
        "query" : {
            "bool" : {
                "must" : [
                    {
                        "match" : {"obj1.name" : "blue"}
                    },
                    {
                        "range" : {"obj1.count" : {"gt" : 5}}
                    }
                ]
            }
        }
    }
}

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.