uid-field.asciidoc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. [[mapping-uid-field]]
  2. === `_uid` field
  3. Each document indexed is associated with a <<mapping-type-field,`_type`>> (see
  4. <<mapping-type>>) and an <<mapping-id-field,`_id`>>. These values are
  5. 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?refresh=true
  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": {
  44. "lang": "painless",
  45. "inline": "doc['_uid']" <4>
  46. }
  47. }
  48. }
  49. }
  50. --------------------------
  51. // CONSOLE
  52. <1> Querying on the `_uid` field (also see the <<query-dsl-ids-query,`ids` query>>)
  53. <2> Aggregating on the `_uid` field
  54. <3> Sorting on the `_uid` field
  55. <4> Accessing the `_uid` field in scripts