field-names-field.asciidoc 1.3 KB

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