Augusto Altman Quaranta
Augusto Altman Quaranta

Reputation: 1576

Wildcard query over _all field on Elasticsearch

I'm trying to perform wildcard queries over the _all field. An example query could be:

GET index/type/_search
{
  "from" : 0,
  "size" : 1000,
  "query" : {
    "bool" : {
      "must" : {
        "wildcard" : {
          "_all" : "*tito*"
        }
      }
    }
  }
}

The thing is that to use a wildcard query the _all field needs to be not_analyzed, otherwise the query won't work. See ES documentation for more info.

I tried to set the mappings over the _all field using this request:

PUT index
{
    "mappings": {
        "type": {
            "_all" : {
              "enabled" : true,
              "index_analyzer": "not_analyzed",
              "search_analyzer": "not_analyzed"
            },
            "_timestamp": {
                "enabled": "true"
            },
            "properties": {
                "someProp": {
                  "type": "date"
                }
            }
        }
    }
}

But I'm getting the error analyzer [not_analyzed] not found for field [_all].

I want to know what I'm doing wrong and if there is another (better) way to perform this kind of queries.

Thanks.-

Upvotes: 1

Views: 1733

Answers (2)

Heval
Heval

Reputation: 348

Most probably you wanted to give option "index": "not_analyzed" Index attribute for a string field, _all is a string field, determines if that field should be analyzed or not.

"search_analyzer" is to set to determine which analyzer should be used for user entered query, which is valid if index attribute is set to analyzed. "index_analyzer" is to set to determine which analyzer should be used for documents, again which is valid if index attribute is set to analyzed.

Upvotes: 1

scottjustin5000
scottjustin5000

Reputation: 1346

Have you tried removing:

"search_analyzer": "not_analyzed"

Also, I wonder how well a wildcard across all properties will scale. Have you looked into NGrams? See the docs here.

Upvotes: 1

Related Questions