blue-sky
blue-sky

Reputation: 53786

Searching for multiple values using REST

I'm attempting to search for documents that contain match a value from list of values.

The list of values are ["AGA>23/180@23221" , "AGA>24/180@23221" ,"AGA>25/180@23221"]

To find the documents a solution is to iterate over the each elements in the list and invoke multiple requests using a query for each element:

query 1:

{
  "query": {
    "term": {
      "mid.keyword": "AGA>23/180@20210212"
    }
  }
}

query 1:

{
  "query": {
    "term": {
      "mid.keyword": "AGA>24/180@20210212"
    }
  }
}

query 3:

{
  "query": {
    "term": {
      "mid.keyword": "AGA>25/180@20210212"
    }
  }
}

Can the search be combined into a single request ? When I try to combine into a single reuqest using payload:

{
  "query": {
    "term": {
      "mid.keyword": ["AGA>23/180@20210212" , "AGA>24/180@20210212" , "AGA>25/180@20210212"]
    }
  }
}

elastic search returns error:

'reason': '[term] query does not support array of values',

Upvotes: 0

Views: 125

Answers (1)

Joe - Check out my books
Joe - Check out my books

Reputation: 16895

Use the terms query instead:

{
  "query": {
    "terms": {
      "mid.keyword": ["AGA>23/180@20210212" , "AGA>24/180@20210212" , "AGA>25/180@20210212"]
    }
  }
}

Upvotes: 1

Related Questions