Home > Back-end >  Elasticsearch exact multiword (array) query for one field
Elasticsearch exact multiword (array) query for one field

Time:10-28

I try to write a query where I have multiple Exact search terms lets say an array of strings like

["Q4 Test WC Schüssel", "Q4_18 Bankerlampen", "MORE_SEARCHTERMS"]

And I have an index with an property data.name and I want to search for each of my array strings inside this ONE field for the exact value and I want all entries back where one of my array strings matches.

 {
 "mappings": {
  "_doc": {
    "country": {
      "type": "keyword"
    },
    "data": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        }

I thought this would be an easy task, but I am not shure if I have the wrong google terms where I search for this problem to get an example query.

CodePudding user response:

Use terms query

GET /_search
{
  "query": {
    "terms": {
      "name.keyword": ["Q4 Test WC Schüssel", "Q4_18 Bankerlampen", "MORE_SEARCHTERMS"]
    }
  }
}
  • Related