field-names-field.asciidoc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. [[mapping-field-names-field]]
  2. === `_field_names` field
  3. The `_field_names` field indexes the names of every field in a document that
  4. contains any value other than `null`. This field is used by the
  5. <<query-dsl-exists-query,`exists`>> and <<query-dsl-missing-query,`missing`>>
  6. queries to find documents that either have or don't have any non-+null+ value
  7. for a particular field.
  8. The value of the `_field_name` field is accessible in queries, aggregations, and
  9. scripts:
  10. [source,js]
  11. --------------------------
  12. # Example documents
  13. PUT my_index/my_type/1
  14. {
  15. "title": "This is a document"
  16. }
  17. PUT my_index/my_type/1
  18. {
  19. "title": "This is another document",
  20. "body": "This document has a body"
  21. }
  22. GET my_index/_search
  23. {
  24. "query": {
  25. "terms": {
  26. "_field_names": [ "title" ] <1>
  27. }
  28. },
  29. "aggs": {
  30. "Field names": {
  31. "terms": {
  32. "field": "_field_names", <2>
  33. "size": 10
  34. }
  35. }
  36. },
  37. "script_fields": {
  38. "Field names": {
  39. "script": "doc['_field_names']" <3>
  40. }
  41. }
  42. }
  43. --------------------------
  44. // AUTOSENSE
  45. <1> Querying on the `_field_names` field (also see the <<query-dsl-exists-query,`exists`>> and <<query-dsl-missing-query,`missing`>> queries)
  46. <2> Aggregating on the `_field_names` field
  47. <3> Accessing the `_field_names` field in scripts (inline scripts must be <<enable-dynamic-scripting,enabled>> for this example to work)