uid-field.asciidoc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. [[mapping-uid-field]]
  2. === `_uid` field
  3. Each document indexed is associated with a <<mapping-type-field,`_type`>> (see
  4. <<all-mapping-types,Mapping Types>>) and an <<mapping-id-field,`_id`>>. These
  5. values are combined as `{type}#{id}` and indexed as the `_uid` field.
  6. The value of the `_uid` field is accessible in queries, aggregations, scripts,
  7. and when sorting:
  8. [source,js]
  9. --------------------------
  10. # Example documents
  11. PUT my_index/my_type/1
  12. {
  13. "text": "Document with ID 1"
  14. }
  15. PUT my_index/my_type/2
  16. {
  17. "text": "Document with ID 2"
  18. }
  19. GET my_index/_search
  20. {
  21. "query": {
  22. "terms": {
  23. "_uid": [ "my_type#1", "my_type#2" ] <1>
  24. }
  25. },
  26. "aggs": {
  27. "UIDs": {
  28. "terms": {
  29. "field": "_uid", <2>
  30. "size": 10
  31. }
  32. }
  33. },
  34. "sort": [
  35. {
  36. "_uid": { <3>
  37. "order": "desc"
  38. }
  39. }
  40. ],
  41. "script_fields": {
  42. "UID": {
  43. "script": "doc['_uid']" <4>
  44. }
  45. }
  46. }
  47. --------------------------
  48. // AUTOSENSE
  49. <1> Querying on the `_uid` field (also see the <<query-dsl-ids-query,`ids` query>>)
  50. <2> Aggregating on the `_uid` field
  51. <3> Sorting on the `_uid` field
  52. <4> Accessing the `_uid` field in scripts (inline scripts must be <<enable-dynamic-scripting,enabled>> for this example to work)