-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add index-time scripts to geo_point field mapper #71861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
romseygeek
merged 7 commits into
elastic:master
from
romseygeek:mapper/geo-point-index-scripts
Apr 20, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4e30b2e
broekn
romseygeek be90486
Merge remote-tracking branch 'origin/master' into mapper/geo-point-in…
romseygeek ddb709f
Add index-time scripts to geo_point field mapper
romseygeek 00a1d1a
tests
romseygeek f5df409
Merge remote-tracking branch 'origin/master' into mapper/geo-point-in…
romseygeek 1d8c67b
Merge remote-tracking branch 'origin/master' into mapper/geo-point-in…
romseygeek 8d65c25
docs
romseygeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
...estTest/resources/rest-api-spec/test/runtime_fields/103_geo_point_calculated_at_index.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| --- | ||
| setup: | ||
| - do: | ||
| indices.create: | ||
| index: locations | ||
| body: | ||
| settings: | ||
| number_of_shards: 1 | ||
| number_of_replicas: 0 | ||
| mappings: | ||
| properties: | ||
| location_from_doc_value: | ||
| type: geo_point | ||
| script: | ||
| source: | | ||
| emit(doc["location"].lat, doc["location"].lon); | ||
| location_from_source: | ||
| type: geo_point | ||
| script: | ||
| source: | | ||
| emit(params._source.location.lat, params._source.location.lon); | ||
| timestamp: | ||
| type: date | ||
| location: | ||
| type: geo_point | ||
| - do: | ||
| bulk: | ||
| index: locations | ||
| refresh: true | ||
| body: | | ||
| {"index":{}} | ||
| {"timestamp": "1998-04-30T14:30:17-05:00", "location" : {"lat": 13.5, "lon" : 34.89}} | ||
| {"index":{}} | ||
| {"timestamp": "1998-04-30T14:30:53-05:00", "location" : {"lat": -7.9, "lon" : 120.78}} | ||
| {"index":{}} | ||
| {"timestamp": "1998-04-30T14:31:12-05:00", "location" : {"lat": 45.78, "lon" : -173.45}} | ||
| {"index":{}} | ||
| {"timestamp": "1998-04-30T14:31:19-05:00", "location" : {"lat": 32.45, "lon" : 45.6}} | ||
| {"index":{}} | ||
| {"timestamp": "1998-04-30T14:31:22-05:00", "location" : {"lat": -63.24, "lon" : 31.0}} | ||
| {"index":{}} | ||
| {"timestamp": "1998-04-30T14:31:27-05:00", "location" : {"lat": 0.0, "lon" : 0.0}} | ||
|
|
||
|
|
||
| --- | ||
| "get mapping": | ||
| - do: | ||
| indices.get_mapping: | ||
| index: locations | ||
| - match: {locations.mappings.properties.location_from_source.type: geo_point } | ||
| - match: | ||
| locations.mappings.properties.location_from_source.script.source: | | ||
| emit(params._source.location.lat, params._source.location.lon); | ||
| - match: {locations.mappings.properties.location_from_source.script.lang: painless } | ||
|
|
||
| --- | ||
| "fetch fields from source": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| sort: timestamp | ||
| fields: [location, location_from_doc_value, location_from_source] | ||
| - match: {hits.total.value: 6} | ||
| - match: {hits.hits.0.fields.location.0.type: "Point" } | ||
| - match: {hits.hits.0.fields.location.0.coordinates: [34.89, 13.5] } | ||
| # calculated from scripts adds annoying extra precision | ||
| - match: { hits.hits.0.fields.location_from_doc_value.0.type: "Point" } | ||
| - match: { hits.hits.0.fields.location_from_doc_value.0.coordinates: [ 34.889999935403466, 13.499999991618097 ] } | ||
| - match: { hits.hits.0.fields.location_from_source.0.type: "Point" } | ||
| - match: { hits.hits.0.fields.location_from_source.0.coordinates: [ 34.889999935403466, 13.499999991618097 ] } | ||
|
|
||
| --- | ||
| "exists query": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| query: | ||
| exists: | ||
| field: location_from_source | ||
| - match: {hits.total.value: 6} | ||
|
|
||
| --- | ||
| "geo bounding box query": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| query: | ||
| geo_bounding_box: | ||
| location_from_source: | ||
| top_left: | ||
| lat: 10 | ||
| lon: -10 | ||
| bottom_right: | ||
| lat: -10 | ||
| lon: 10 | ||
| - match: {hits.total.value: 1} | ||
|
|
||
| --- | ||
| "geo shape query": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| query: | ||
| geo_shape: | ||
| location_from_source: | ||
| shape: | ||
| type: "envelope" | ||
| coordinates: [ [ -10, 10 ], [ 10, -10 ] ] | ||
| - match: {hits.total.value: 1} | ||
|
|
||
| --- | ||
| "geo distance query": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| query: | ||
| geo_distance: | ||
| distance: "2000km" | ||
| location_from_source: | ||
| lat: 0 | ||
| lon: 0 | ||
| - match: {hits.total.value: 1} | ||
|
|
||
| --- | ||
| "bounds agg": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| aggs: | ||
| bounds: | ||
| geo_bounds: | ||
| field: "location" | ||
| wrap_longitude: false | ||
| bounds_from_doc_value: | ||
| geo_bounds: | ||
| field: "location_from_doc_value" | ||
| wrap_longitude: false | ||
| bounds_from_source: | ||
| geo_bounds: | ||
| field: "location_from_source" | ||
| wrap_longitude: false | ||
| - match: {hits.total.value: 6} | ||
| - match: {aggregations.bounds.bounds.top_left.lat: 45.7799999602139 } | ||
| - match: {aggregations.bounds.bounds.top_left.lon: -173.4500000718981 } | ||
| - match: {aggregations.bounds.bounds.bottom_right.lat: -63.240000014193356 } | ||
| - match: {aggregations.bounds.bounds.bottom_right.lon: 120.77999993227422 } | ||
| - match: {aggregations.bounds_from_doc_value.bounds.top_left.lat: 45.7799999602139 } | ||
| - match: {aggregations.bounds_from_doc_value.bounds.top_left.lon: -173.4500000718981 } | ||
| - match: {aggregations.bounds_from_doc_value.bounds.bottom_right.lat: -63.240000014193356 } | ||
| - match: {aggregations.bounds_from_doc_value.bounds.bottom_right.lon: 120.77999993227422 } | ||
| - match: {aggregations.bounds_from_source.bounds.top_left.lat: 45.7799999602139 } | ||
| - match: {aggregations.bounds_from_source.bounds.top_left.lon: -173.4500000718981 } | ||
| - match: {aggregations.bounds_from_source.bounds.bottom_right.lat: -63.240000014193356 } | ||
| - match: {aggregations.bounds_from_source.bounds.bottom_right.lon: 120.77999993227422 } | ||
|
|
||
| --- | ||
| "geo_distance sort": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| sort: | ||
| _geo_distance: | ||
| location_from_source: | ||
| lat: 0.0 | ||
| lon: 0.0 | ||
| - match: {hits.total.value: 6} | ||
| - match: {hits.hits.0._source.location.lat: 0.0 } | ||
| - match: {hits.hits.0._source.location.lon: 0.0 } | ||
| - match: {hits.hits.1._source.location.lat: 13.5 } | ||
| - match: {hits.hits.1._source.location.lon: 34.89 } | ||
| - match: {hits.hits.2._source.location.lat: 32.45 } | ||
| - match: {hits.hits.2._source.location.lon: 45.6 } | ||
| - match: {hits.hits.3._source.location.lat: -63.24 } | ||
| - match: {hits.hits.3._source.location.lon: 31.0 } | ||
|
|
||
| --- | ||
| "distance_feature query": | ||
| - do: | ||
| search: | ||
| index: locations | ||
| body: | ||
| query: | ||
| bool: | ||
| should: | ||
| distance_feature: | ||
| field: "location" | ||
| pivot: "1000km" | ||
| origin: [0.0, 0.0] | ||
|
|
||
| - match: {hits.total.value: 6} | ||
| - match: {hits.hits.0._source.location.lat: 0.0 } | ||
| - match: {hits.hits.0._source.location.lon: 0.0 } | ||
| - match: {hits.hits.1._source.location.lat: 13.5 } | ||
| - match: {hits.hits.1._source.location.lon: 34.89 } | ||
| - match: {hits.hits.2._source.location.lat: 32.45 } | ||
| - match: {hits.hits.2._source.location.lon: 45.6 } | ||
| - match: {hits.hits.3._source.location.lat: -63.24 } | ||
| - match: {hits.hits.3._source.location.lon: 31.0 } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grr I forgot about the mappers that override parse when I added this to the base class. Is it worth extracting the check to a common method so that it can be called from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to rework parse/parseCreateField anyway, as it's very confusing that we have these two methods with the same signature that do almost exactly the same thing. Can we consider this a band-aid until we tidy up in a followup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, anyways the test is unified and tests the error message, so we ensure that it is always the same one