field-names-field.asciidoc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 and scripts:
  8. [source,js]
  9. --------------------------
  10. # Example documents
  11. PUT my_index/my_type/1
  12. {
  13. "title": "This is a document"
  14. }
  15. PUT my_index/my_type/1
  16. {
  17. "title": "This is another document",
  18. "body": "This document has a body"
  19. }
  20. GET my_index/_search
  21. {
  22. "query": {
  23. "terms": {
  24. "_field_names": [ "title" ] <1>
  25. }
  26. },
  27. "script_fields": {
  28. "Field names": {
  29. "script": "doc['_field_names']" <2>
  30. }
  31. }
  32. }
  33. --------------------------
  34. // AUTOSENSE
  35. <1> Querying on the `_field_names` field (also see the <<query-dsl-exists-query,`exists`>> query)
  36. <2> Accessing the `_field_names` field in scripts (inline scripts must be <<enable-dynamic-scripting,enabled>> for this example to work)