| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 | [[mapping-all-field]]=== `_all` fieldThe `_all` field is a special _catch-all_ field which concatenates the valuesof all of the other fields into one big string, using space as a delimiter, which is then<<analysis,analyzed>> and indexed, but not stored.  This means that it can besearched, but not retrieved.The `_all` field allows you to search for values in documents without knowingwhich field contains the value.  This makes it a useful option when gettingstarted with a new dataset. For instance:[source,js]--------------------------------PUT my_index/user/1 <1>{  "first_name":    "John",  "last_name":     "Smith",  "date_of_birth": "1970-10-24"}GET my_index/_search{  "query": {    "match": {      "_all": "john smith 1970"    }  }}--------------------------------// CONSOLE<1> The `_all` field will contain the terms: [ `"john"`, `"smith"`, `"1970"`, `"10"`, `"24"` ][NOTE].All values treated as strings=============================================================================The `date_of_birth` field in the above example is recognised as a `date` fieldand so will index a single term representing `1970-10-24 00:00:00 UTC`. The`_all` field, however, treats all values as strings, so the date value isindexed as the three string terms: `"1970"`, `"24"`, `"10"`.It is important to note that the `_all` field combines the original valuesfrom each field as a string. It does not combine the _terms_ from each field.=============================================================================The `_all` field is just a <<text,`text`>> field, and accepts the sameparameters that  other string fields accept, including `analyzer`,`term_vectors`, `index_options`, and `store`.The `_all` field can be useful, especially when exploring new data usingsimple filtering.  However, by concatenating field values into one big string,the `_all` field loses the distinction between short fields (more relevant)and long fields (less relevant). For use cases where search relevance isimportant, it is better to query individual fields specifically.The `_all` field is not free: it requires extra CPU cycles and uses more diskspace. If not needed, it can be completely <<disabling-all-field,disabled>> orcustomised on a <<include-in-all,per-field basis>>.[[querying-all-field]]==== Using the `_all` field in queriesThe <<query-dsl-query-string-query,`query_string`>> and<<query-dsl-simple-query-string-query,`simple_query_string`>> queries querythe `_all` field by default, unless another field is specified:[source,js]--------------------------------GET _search{  "query": {    "query_string": {      "query": "john smith 1970"    }  }}--------------------------------// CONSOLEThe same goes for the `?q=` parameter in <<search-uri-request, URI searchrequests>> (which is rewritten to a `query_string` query internally):[source,js]--------------------------------GET _search?q=john+smith+1970--------------------------------Other queries, such as the <<query-dsl-match-query,`match`>> and<<query-dsl-term-query,`term`>> queries require you to specifythe `_all` field explicitly, as per the<<mapping-all-field,first example>>.[[disabling-all-field]]==== Disabling the `_all` fieldThe `_all` field can be completely disabled per-type by setting `enabled` to`false`:[source,js]--------------------------------PUT my_index{  "mappings": {    "type_1": { <1>      "properties": {...}    },    "type_2": { <2>      "_all": {        "enabled": false      },      "properties": {...}    }  }}--------------------------------// CONSOLE// TEST[s/\.\.\.//]<1> The `_all` field in `type_1` is enabled.<2> The `_all` field in `type_2` is completely disabled.If the `_all` field is disabled, then URI search requests and the`query_string` and `simple_query_string` queries will not be able to use itfor queries (see <<querying-all-field>>).  You can configure them to use adifferent field with the `index.query.default_field` setting:[source,js]--------------------------------PUT my_index{  "mappings": {    "my_type": {      "_all": {        "enabled": false <1>      },      "properties": {        "content": {          "type": "text"        }      }    }  },  "settings": {    "index.query.default_field": "content" <2>  }}--------------------------------// CONSOLE<1> The `_all` field is disabled for the `my_type` type.<2> The `query_string` query will default to querying the `content` field in this index.[[excluding-from-all]]==== Excluding fields from `_all`Individual fields can be included or excluded from the `_all` field with the<<include-in-all,`include_in_all`>> setting.[[all-field-and-boosting]]==== Index boosting and the `_all` fieldIndividual fields can be _boosted_ at index time, with the <<mapping-boost,`boost`>>parameter. The `_all` field takes these boosts into account:[source,js]--------------------------------PUT myindex{  "mappings": {    "mytype": {      "properties": {        "title": { <1>          "type": "text",          "boost": 2        },        "content": { <1>          "type": "text"        }      }    }  }}--------------------------------// CONSOLE<1> When querying the `_all` field, words that originated in the    `title` field are twice as relevant as words that originated in    the `content` field.WARNING: Using index-time boosting with the `_all` field has a significantimpact on query performance. Usually the better solution is to query fieldsindividually, with optional query time boosting.[[custom-all-fields]]==== Custom `_all` fieldsWhile there is only a single `_all` field per index, the <<copy-to,`copy_to`>>parameter allows the creation of multiple __custom `_all` fields__. Forinstance, `first_name` and `last_name` fields can be combined together intothe `full_name` field:[source,js]--------------------------------PUT myindex{  "mappings": {    "mytype": {      "properties": {        "first_name": {          "type":    "text",          "copy_to": "full_name" <1>        },        "last_name": {          "type":    "text",          "copy_to": "full_name" <1>        },        "full_name": {          "type":    "text"        }      }    }  }}PUT myindex/mytype/1{  "first_name": "John",  "last_name": "Smith"}GET myindex/_search{  "query": {    "match": {      "full_name": "John Smith"    }  }}--------------------------------// CONSOLE<1> The `first_name` and `last_name` values are copied to the `full_name` field.[[highlighting-all-field]]==== Highlighting and the `_all` fieldA field can only be used for <<search-request-highlighting,highlighting>>  ifthe original string value is available, either from the<<mapping-source-field,`_source`>>  field or as a stored field.The `_all` field is not present in the `_source` field and it is not stored bydefault, and so cannot be highlighted. There are two options. Either<<all-field-store,store the `_all` field>> or highlight the<<all-highlight-fields,original fields>>.[[all-field-store]]===== Store the `_all` fieldIf `store` is set to `true`, then the original field value is retrievable andcan be highlighted:[source,js]--------------------------------PUT myindex{  "mappings": {    "mytype": {      "_all": {        "store": true      }    }  }}PUT myindex/mytype/1{  "first_name": "John",  "last_name": "Smith"}GET _search{  "query": {    "match": {      "_all": "John Smith"    }  },  "highlight": {    "fields": {      "_all": {}    }  }}--------------------------------// CONSOLEOf course, storing the `_all` field will use significantly more disk spaceand, because it is a combination of other fields, it may result in oddhighlighting results.The `_all` field also accepts the `term_vector` and `index_options`parameters, allowing the use of the fast vector highlighter and the postingshighlighter.[[all-highlight-fields]]===== Highlight original fieldsYou can query the `_all` field, but use the original fields for highlighting as follows:[source,js]--------------------------------PUT myindex{  "mappings": {    "mytype": {      "_all": {}    }  }}PUT myindex/mytype/1{  "first_name": "John",  "last_name": "Smith"}GET _search{  "query": {    "match": {      "_all": "John Smith" <1>    }  },  "highlight": {    "fields": {      "*_name": { <2>        "require_field_match": false  <3>      }    }  }}--------------------------------// CONSOLE<1> The query inspects the `_all` field to find matching documents.<2> Highlighting is performed on the two name fields, which are available from the `_source`.<3> The query wasn't run against the name fields, so set `require_field_match` to `false`.
 |