1
0

uid-field.asciidoc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. [[mapping-uid-field]]
  2. === `_uid` field
  3. deprecated[6.0.0, Now that types have been removed, documents are uniquely
  4. identified by their `_id` and the `_uid` field has only been kept as a view
  5. over the `_id` field for backward compatibility.]
  6. Each document indexed is associated with a <<mapping-type-field,`_type`>> (see
  7. <<mapping-type>>) and an <<mapping-id-field,`_id`>>. These values are
  8. combined as `{type}#{id}` and indexed as the `_uid` field.
  9. The value of the `_uid` field is accessible in queries, aggregations, scripts,
  10. and when sorting:
  11. [source,js]
  12. --------------------------
  13. # Example documents
  14. PUT my_index/my_type/1
  15. {
  16. "text": "Document with ID 1"
  17. }
  18. PUT my_index/my_type/2?refresh=true
  19. {
  20. "text": "Document with ID 2"
  21. }
  22. --------------------------
  23. // CONSOLE
  24. [source,js]
  25. --------------------------
  26. GET my_index/_search
  27. {
  28. "query": {
  29. "terms": {
  30. "_uid": [ "my_type#1", "my_type#2" ] <1>
  31. }
  32. },
  33. "aggs": {
  34. "UIDs": {
  35. "terms": {
  36. "field": "_uid", <2>
  37. "size": 10
  38. }
  39. }
  40. },
  41. "sort": [
  42. {
  43. "_uid": { <3>
  44. "order": "desc"
  45. }
  46. }
  47. ],
  48. "script_fields": {
  49. "UID": {
  50. "script": {
  51. "lang": "painless",
  52. "source": "doc['_uid']" <4>
  53. }
  54. }
  55. }
  56. }
  57. --------------------------
  58. // CONSOLE
  59. // TEST[continued]
  60. // TEST[warning:Fielddata access on the _uid field is deprecated, use _id instead]
  61. <1> Querying on the `_uid` field (also see the <<query-dsl-ids-query,`ids` query>>)
  62. <2> Aggregating on the `_uid` field
  63. <3> Sorting on the `_uid` field
  64. <4> Accessing the `_uid` field in scripts