2014-05-20 11:34:00 -04:00
|
|
|
[[mapping-field-names-field]]
|
2015-07-19 19:24:29 -04:00
|
|
|
=== `_field_names` field
|
|
|
|
|
|
|
|
The `_field_names` field indexes the names of every field in a document that
|
|
|
|
contains any value other than `null`. This field is used by the
|
2015-12-11 14:07:57 -05:00
|
|
|
<<query-dsl-exists-query,`exists`>> query to find documents that
|
|
|
|
either have or don't have any non-+null+ value for a particular field.
|
2015-07-19 19:24:29 -04:00
|
|
|
|
2017-04-19 05:57:37 -04:00
|
|
|
The value of the `_field_names` field is accessible in queries:
|
2015-07-19 19:24:29 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------
|
|
|
|
# Example documents
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/1
|
2015-07-19 19:24:29 -04:00
|
|
|
{
|
|
|
|
"title": "This is a document"
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/2?refresh=true
|
2015-07-19 19:24:29 -04:00
|
|
|
{
|
|
|
|
"title": "This is another document",
|
|
|
|
"body": "This document has a body"
|
|
|
|
}
|
|
|
|
|
|
|
|
GET my_index/_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"terms": {
|
|
|
|
"_field_names": [ "title" ] <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2015-07-19 19:24:29 -04:00
|
|
|
|
2017-04-19 05:57:37 -04:00
|
|
|
<1> Querying on the `_field_names` field (also see the <<query-dsl-exists-query,`exists`>> query)
|
2017-10-06 10:49:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
==== Disabling `_field_names`
|
|
|
|
|
|
|
|
Because `_field_names` introduce some index-time overhead, you might want to
|
|
|
|
disable this field if you want to optimize for indexing speed and do not need
|
|
|
|
`exists` queries.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT tweets
|
|
|
|
{
|
|
|
|
"mappings": {
|
2017-12-14 11:47:53 -05:00
|
|
|
"_doc": {
|
2017-10-06 10:49:15 -04:00
|
|
|
"_field_names": {
|
|
|
|
"enabled": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// CONSOLE
|