|
| 1 | +[role="xpack"] |
| 2 | +[testenv="basic"] |
| 3 | + |
| 4 | +[[unsigned-long]] |
| 5 | +=== Unsigned long data type |
| 6 | +Unsigned long is a numeric field type that represents an unsigned 64-bit |
| 7 | +integer with a minimum value of 0 and a maximum value of +2^64^-1+ |
| 8 | +(from 0 to 18446744073709551615 inclusive). |
| 9 | + |
| 10 | +[source,console] |
| 11 | +-------------------------------------------------- |
| 12 | +PUT my_index |
| 13 | +{ |
| 14 | + "mappings": { |
| 15 | + "properties": { |
| 16 | + "my_counter": { |
| 17 | + "type": "unsigned_long" |
| 18 | + } |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | +-------------------------------------------------- |
| 23 | + |
| 24 | +Unsigned long can be indexed in a numeric or string form, |
| 25 | +representing integer values in the range [0, 18446744073709551615]. |
| 26 | +They can't have a decimal part. |
| 27 | + |
| 28 | +[source,console] |
| 29 | +-------------------------------- |
| 30 | +POST /my_index/_bulk?refresh |
| 31 | +{"index":{"_id":1}} |
| 32 | +{"my_counter": 0} |
| 33 | +{"index":{"_id":2}} |
| 34 | +{"my_counter": 9223372036854775808} |
| 35 | +{"index":{"_id":3}} |
| 36 | +{"my_counter": 18446744073709551614} |
| 37 | +{"index":{"_id":4}} |
| 38 | +{"my_counter": 18446744073709551615} |
| 39 | +-------------------------------- |
| 40 | +//TEST[continued] |
| 41 | + |
| 42 | +Term queries accept any numbers in a numeric or string form. |
| 43 | + |
| 44 | +[source,console] |
| 45 | +-------------------------------- |
| 46 | +GET /my_index/_search |
| 47 | +{ |
| 48 | + "query": { |
| 49 | + "term" : { |
| 50 | + "my_counter" : 18446744073709551615 |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +-------------------------------- |
| 55 | +//TEST[continued] |
| 56 | + |
| 57 | +Range query terms can contain values with decimal parts. |
| 58 | +In this case {es} converts them to integer values: |
| 59 | +`gte` and `gt` terms are converted to the nearest integer up inclusive, |
| 60 | +and `lt` and `lte` ranges are converted to the nearest integer down inclusive. |
| 61 | + |
| 62 | +It is recommended to pass ranges as strings to ensure they are parsed |
| 63 | +without any loss of precision. |
| 64 | + |
| 65 | +[source,console] |
| 66 | +-------------------------------- |
| 67 | +GET /my_index/_search |
| 68 | +{ |
| 69 | + "query": { |
| 70 | + "range" : { |
| 71 | + "my_counter" : { |
| 72 | + "gte" : "9223372036854775808.5", |
| 73 | + "lte" : "18446744073709551615" |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +-------------------------------- |
| 79 | +//TEST[continued] |
| 80 | + |
| 81 | + |
| 82 | +For queries with sort on an `unsigned_long` field, |
| 83 | +for a particular document {es} returns a sort value of the type `long` |
| 84 | +if the value of this document is within the range of long values, |
| 85 | +or of the type `BigInteger` if the value exceeds this range. |
| 86 | + |
| 87 | +NOTE: REST clients need to be able to handle big integer values |
| 88 | +in JSON to support this field type correctly. |
| 89 | + |
| 90 | +[source,console] |
| 91 | +-------------------------------- |
| 92 | +GET /my_index/_search |
| 93 | +{ |
| 94 | + "query": { |
| 95 | + "match_all" : {} |
| 96 | + }, |
| 97 | + "sort" : {"my_counter" : "desc"} |
| 98 | +} |
| 99 | +-------------------------------- |
| 100 | +//TEST[continued] |
| 101 | + |
| 102 | +Similarly to sort values, script values of an `unsigned_long` field |
| 103 | +return a `Number` representing a `Long` or `BigInteger`. |
| 104 | +The same values: `Long` or `BigInteger` are used for `terms` aggregations. |
| 105 | + |
| 106 | +==== Queries with mixed numeric types |
| 107 | + |
| 108 | +Searches with mixed numeric types one of which is `unsigned_long` are |
| 109 | +supported, except queries with sort. Thus, a sort query across two indexes |
| 110 | +where the same field name has an `unsigned_long` type in one index, |
| 111 | +and `long` type in another, doesn't produce correct results and must |
| 112 | +be avoided. If there is a need for such kind of sorting, script based sorting |
| 113 | +can be used instead. |
| 114 | + |
| 115 | +Aggregations across several numeric types one of which is `unsigned_long` are |
| 116 | +supported. In this case, values are converted to the `double` type. |
0 commit comments