Finding multiple exact value


(dina) #1

I would like to query elastic search , query if field is one of a list
how do I do that in elastic 6.0.0?
for example these are my documents:

{"name" : "jim","company": "a"}
{"name" : "jack","company": "a"}
{"name" : "joe","company": "b"}
{"name" : "foo","company": "b"}
{"name" : "bar","company": "c"}
{"name" : "boe","company": "c"}
{"name" : "jee","company": "d"}

Id like to return all entries which have company a or b

i tried this:

curl  -u elastic:password -XPOST 'localhost:9243/my-index/_search?size=2000&pretty' -H 'Content-Type: application/json' -d'
{
  "size": 2000,
  "query": {
    "bool": {
      "must": [
        {"term": {"company": ["a","b"]}}

      ]
    }
  }
}'

but I get an error [term] query does not support array of values

note: I need a solution that would let me use an array, since I need to match ~100 options


(David Pilato) #2

You can use a Terms query instead. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html