|
| 1 | +--- |
| 2 | +setup: |
| 3 | + - do: |
| 4 | + indices.create: |
| 5 | + index: locations |
| 6 | + body: |
| 7 | + settings: |
| 8 | + number_of_shards: 1 |
| 9 | + number_of_replicas: 0 |
| 10 | + mappings: |
| 11 | + properties: |
| 12 | + location_from_doc_value: |
| 13 | + type: geo_point |
| 14 | + script: |
| 15 | + source: | |
| 16 | + emit(doc["location"].lat, doc["location"].lon); |
| 17 | + location_from_source: |
| 18 | + type: geo_point |
| 19 | + script: |
| 20 | + source: | |
| 21 | + emit(params._source.location.lat, params._source.location.lon); |
| 22 | + timestamp: |
| 23 | + type: date |
| 24 | + location: |
| 25 | + type: geo_point |
| 26 | + - do: |
| 27 | + bulk: |
| 28 | + index: locations |
| 29 | + refresh: true |
| 30 | + body: | |
| 31 | + {"index":{}} |
| 32 | + {"timestamp": "1998-04-30T14:30:17-05:00", "location" : {"lat": 13.5, "lon" : 34.89}} |
| 33 | + {"index":{}} |
| 34 | + {"timestamp": "1998-04-30T14:30:53-05:00", "location" : {"lat": -7.9, "lon" : 120.78}} |
| 35 | + {"index":{}} |
| 36 | + {"timestamp": "1998-04-30T14:31:12-05:00", "location" : {"lat": 45.78, "lon" : -173.45}} |
| 37 | + {"index":{}} |
| 38 | + {"timestamp": "1998-04-30T14:31:19-05:00", "location" : {"lat": 32.45, "lon" : 45.6}} |
| 39 | + {"index":{}} |
| 40 | + {"timestamp": "1998-04-30T14:31:22-05:00", "location" : {"lat": -63.24, "lon" : 31.0}} |
| 41 | + {"index":{}} |
| 42 | + {"timestamp": "1998-04-30T14:31:27-05:00", "location" : {"lat": 0.0, "lon" : 0.0}} |
| 43 | +
|
| 44 | +
|
| 45 | +--- |
| 46 | +"get mapping": |
| 47 | + - do: |
| 48 | + indices.get_mapping: |
| 49 | + index: locations |
| 50 | + - match: {locations.mappings.properties.location_from_source.type: geo_point } |
| 51 | + - match: |
| 52 | + locations.mappings.properties.location_from_source.script.source: | |
| 53 | + emit(params._source.location.lat, params._source.location.lon); |
| 54 | + - match: {locations.mappings.properties.location_from_source.script.lang: painless } |
| 55 | + |
| 56 | +--- |
| 57 | +"fetch fields from source": |
| 58 | + - do: |
| 59 | + search: |
| 60 | + index: locations |
| 61 | + body: |
| 62 | + sort: timestamp |
| 63 | + fields: [location, location_from_doc_value, location_from_source] |
| 64 | + - match: {hits.total.value: 6} |
| 65 | + - match: {hits.hits.0.fields.location.0.type: "Point" } |
| 66 | + - match: {hits.hits.0.fields.location.0.coordinates: [34.89, 13.5] } |
| 67 | + # calculated from scripts adds annoying extra precision |
| 68 | + - match: { hits.hits.0.fields.location_from_doc_value.0.type: "Point" } |
| 69 | + - match: { hits.hits.0.fields.location_from_doc_value.0.coordinates: [ 34.889999935403466, 13.499999991618097 ] } |
| 70 | + - match: { hits.hits.0.fields.location_from_source.0.type: "Point" } |
| 71 | + - match: { hits.hits.0.fields.location_from_source.0.coordinates: [ 34.889999935403466, 13.499999991618097 ] } |
| 72 | + |
| 73 | +--- |
| 74 | +"exists query": |
| 75 | + - do: |
| 76 | + search: |
| 77 | + index: locations |
| 78 | + body: |
| 79 | + query: |
| 80 | + exists: |
| 81 | + field: location_from_source |
| 82 | + - match: {hits.total.value: 6} |
| 83 | + |
| 84 | +--- |
| 85 | +"geo bounding box query": |
| 86 | + - do: |
| 87 | + search: |
| 88 | + index: locations |
| 89 | + body: |
| 90 | + query: |
| 91 | + geo_bounding_box: |
| 92 | + location_from_source: |
| 93 | + top_left: |
| 94 | + lat: 10 |
| 95 | + lon: -10 |
| 96 | + bottom_right: |
| 97 | + lat: -10 |
| 98 | + lon: 10 |
| 99 | + - match: {hits.total.value: 1} |
| 100 | + |
| 101 | +--- |
| 102 | +"geo shape query": |
| 103 | + - do: |
| 104 | + search: |
| 105 | + index: locations |
| 106 | + body: |
| 107 | + query: |
| 108 | + geo_shape: |
| 109 | + location_from_source: |
| 110 | + shape: |
| 111 | + type: "envelope" |
| 112 | + coordinates: [ [ -10, 10 ], [ 10, -10 ] ] |
| 113 | + - match: {hits.total.value: 1} |
| 114 | + |
| 115 | +--- |
| 116 | +"geo distance query": |
| 117 | + - do: |
| 118 | + search: |
| 119 | + index: locations |
| 120 | + body: |
| 121 | + query: |
| 122 | + geo_distance: |
| 123 | + distance: "2000km" |
| 124 | + location_from_source: |
| 125 | + lat: 0 |
| 126 | + lon: 0 |
| 127 | + - match: {hits.total.value: 1} |
| 128 | + |
| 129 | +--- |
| 130 | +"bounds agg": |
| 131 | + - do: |
| 132 | + search: |
| 133 | + index: locations |
| 134 | + body: |
| 135 | + aggs: |
| 136 | + bounds: |
| 137 | + geo_bounds: |
| 138 | + field: "location" |
| 139 | + wrap_longitude: false |
| 140 | + bounds_from_doc_value: |
| 141 | + geo_bounds: |
| 142 | + field: "location_from_doc_value" |
| 143 | + wrap_longitude: false |
| 144 | + bounds_from_source: |
| 145 | + geo_bounds: |
| 146 | + field: "location_from_source" |
| 147 | + wrap_longitude: false |
| 148 | + - match: {hits.total.value: 6} |
| 149 | + - match: {aggregations.bounds.bounds.top_left.lat: 45.7799999602139 } |
| 150 | + - match: {aggregations.bounds.bounds.top_left.lon: -173.4500000718981 } |
| 151 | + - match: {aggregations.bounds.bounds.bottom_right.lat: -63.240000014193356 } |
| 152 | + - match: {aggregations.bounds.bounds.bottom_right.lon: 120.77999993227422 } |
| 153 | + - match: {aggregations.bounds_from_doc_value.bounds.top_left.lat: 45.7799999602139 } |
| 154 | + - match: {aggregations.bounds_from_doc_value.bounds.top_left.lon: -173.4500000718981 } |
| 155 | + - match: {aggregations.bounds_from_doc_value.bounds.bottom_right.lat: -63.240000014193356 } |
| 156 | + - match: {aggregations.bounds_from_doc_value.bounds.bottom_right.lon: 120.77999993227422 } |
| 157 | + - match: {aggregations.bounds_from_source.bounds.top_left.lat: 45.7799999602139 } |
| 158 | + - match: {aggregations.bounds_from_source.bounds.top_left.lon: -173.4500000718981 } |
| 159 | + - match: {aggregations.bounds_from_source.bounds.bottom_right.lat: -63.240000014193356 } |
| 160 | + - match: {aggregations.bounds_from_source.bounds.bottom_right.lon: 120.77999993227422 } |
| 161 | + |
| 162 | +--- |
| 163 | +"geo_distance sort": |
| 164 | + - do: |
| 165 | + search: |
| 166 | + index: locations |
| 167 | + body: |
| 168 | + sort: |
| 169 | + _geo_distance: |
| 170 | + location_from_source: |
| 171 | + lat: 0.0 |
| 172 | + lon: 0.0 |
| 173 | + - match: {hits.total.value: 6} |
| 174 | + - match: {hits.hits.0._source.location.lat: 0.0 } |
| 175 | + - match: {hits.hits.0._source.location.lon: 0.0 } |
| 176 | + - match: {hits.hits.1._source.location.lat: 13.5 } |
| 177 | + - match: {hits.hits.1._source.location.lon: 34.89 } |
| 178 | + - match: {hits.hits.2._source.location.lat: 32.45 } |
| 179 | + - match: {hits.hits.2._source.location.lon: 45.6 } |
| 180 | + - match: {hits.hits.3._source.location.lat: -63.24 } |
| 181 | + - match: {hits.hits.3._source.location.lon: 31.0 } |
| 182 | + |
| 183 | +--- |
| 184 | +"distance_feature query": |
| 185 | + - do: |
| 186 | + search: |
| 187 | + index: locations |
| 188 | + body: |
| 189 | + query: |
| 190 | + bool: |
| 191 | + should: |
| 192 | + distance_feature: |
| 193 | + field: "location" |
| 194 | + pivot: "1000km" |
| 195 | + origin: [0.0, 0.0] |
| 196 | + |
| 197 | + - match: {hits.total.value: 6} |
| 198 | + - match: {hits.hits.0._source.location.lat: 0.0 } |
| 199 | + - match: {hits.hits.0._source.location.lon: 0.0 } |
| 200 | + - match: {hits.hits.1._source.location.lat: 13.5 } |
| 201 | + - match: {hits.hits.1._source.location.lon: 34.89 } |
| 202 | + - match: {hits.hits.2._source.location.lat: 32.45 } |
| 203 | + - match: {hits.hits.2._source.location.lon: 45.6 } |
| 204 | + - match: {hits.hits.3._source.location.lat: -63.24 } |
| 205 | + - match: {hits.hits.3._source.location.lon: 31.0 } |
| 206 | + |
0 commit comments