Search code examples
elasticsearchelasticsearch-6

ElasticSearch: Using match_phrase for all fields


As a user of ElasticSearch 5, I have been using something like this to search for a given phrase in all fields:

GET /my_index/_search
{
  "query": {
    "match_phrase": {
      "_all": "this is a phrase"
    }
  }
}

Now, the _all field is going away, and match_phrase does not seem to work like query_string, where you can simply use something like this to run a search for all fields:

"query": {
  "query_string": {
    "query": "word"
  }
}

What is the alternative for a exact phrase search for all fields without using the _all field from version 6.0?

I have many fields per document so specifying all of them in the query is not really a solution for me.


Solution

  • You can find answer in Elasticsearch documentation https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html It says:

    Use a custom field and the mapping copy_to parameter

    So, you have to create custom fields in source, and copy all other fields to it.