How could I search an array of terms using wildcard


(Gabriel Pellegrini Maciel) #1

I'm looking for a way to search an array of items where should have wildcards in their extremities.
I tried to use query_string, but this search does not allow an array search.

    {"query": {
            "bool": {
              "must": [
                {
                  "query_string": {
                    "query": ["*item1*","*item2*"],
                    "fields": [
                      "fiscalID"
                    ],
                    "default_operator": "OR"
                  }
                }
              ]
          }
      }
    }

If someone has any solution I will really appreciate it.
Thanks.


(Abdon Pijpelink) #2

You do not need to provide an array of search terms. If you provide the terms in a single string, the query_string query will break it up wherever it finds an operator (in this case the wildcards). Try this:

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "*item1* *item2*",
            "fields": [
              "fiscalID"
            ]
          }
        }
      ]
    }
  }
}

OR is already the default operator, you can omit that.