aysh
aysh

Reputation: 599

How to match elastic search query partial match multiple query?

My DSL query is below

GET index_name/_search
{
"query" : {
    "query_string" : {
      "query" : "*avi*",
      "fields" : [
        "data.name"
      ]
    }}}

I need to add "query" : "*ojh*" also.

Below query not working

GET index_name/_search
{
"query" : {
    "query_string" : {
      "query" : "*avi*",
      "query" : "*ojh*",
      "fields" : [
        "data.name"
      ]
    }}}

Upvotes: 0

Views: 412

Answers (1)

Val
Val

Reputation: 217294

You need to leverage the bool/should query and add two query_string queries:

{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "*avi*",
            "fields": [
              "data.name"
            ]
          }
        },
        {
          "query_string": {
            "query": "*ojh*",
            "fields": [
              "data.name"
            ]
          }
        }
      ]
    }
  }
}

Just note, though, that doing infix searches like this can kill the performance of your cluster. See this thread on how to properly do "substring" searches.

Upvotes: 1

Related Questions