uid-field.asciidoc 1.6 KB

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