19

I am trying to build on this query a little bit. The index I am searching also has a field "entity" with an id. So a few records will have "entity" : 16, "entity" 156 etc, depending on the id of the entity. I need to expand this query in such a way that I can pass an array or some list of values in, such as {:term => {:entity => [1, 16, 100]}} and get back records that have one of these integers as their entity value. I haven't had any luck so far, can someone help me?

{ 
  "query" : {

    "bool" : {
      "must" : [
        {
          "term" : {"user_type" : "alpha"}
        }, 
        { 
          "term" :{"area" : "16"}
        }
      ], 
      "must_not" : [], 
      "should" :   []
    }
  }, 
  "filter": {
    "or" : [{
       "and" : [
          { "term" : { "area" : "16" } },
          { "term" : { "date" : "05072013" } }
       ]
    }, {
       "and" : [
          { "term" : { "area" : "16" } },
          { "term" : { "date" : "blank" } }
       ]
    }


    ]
  },
"from" : 0,
"size" : 100 
}

1 Answer 1

34

Use "terms" instead of "term".

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html

{ "terms" : { "entity" : [ 123, 1234, ... ] }}

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

2 Comments

this query will contact with AND or with OR ? i want to check my condition with OR like: in above query entity=123 OR entity=1234 so on. how to write that query ?
@DeepParekh Were you able to write the query for the above comment? AND or OR? I have something like this. (I have to pass multiple values of extension to filter. Can you help me to solve this)Right now I could only send one value of extension. What if I have to pass multiple values of extension for filter query? .Filter(ft => ft.Term(t => t.Field("content_type").Value(extension)))))

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.