[BUG] Search for all documents and sort them by the distance from the provided point 3.0.0
Describe the bug
opensearch 3.0.0
GET testindex1/_search
{
"sort": [
{
"_geo_distance": {
"point": [59, -54],
"order": "asc",
"unit": "m",
"distance_type": "arc",
"mode": "min",
"ignore_unmapped": true
}
}
],
"query": {
"match_all": {}
}
}
When the unit is “km” or the order is “desc”, the error message is as follows:
"failures": [
{
"shard": 0,
"index": "products",
"node": "FiW_d2umSbKb6M-sNf0vxw",
"reason": {
"type": "null_pointer_exception",
"reason": """Cannot invoke "String.endsWith(String)" because "field" is null"""
}
}
]
Expected behavior
https://docs.opensearch.org/docs/latest/search-plugins/searching-data/sort/
To Reproduce
dev_tools
PUT products
{
"mappings": {
"properties":{
"location": {
"type": "geo_point"
}
}
}
}
POST _bulk
{"create":{"_index": "products", "_id": "1"}}
{"name":"aaaa","location":{"lat":38.0267,"lon":114.4572}}
{"create":{"_index": "products", "_id": "59"}}
{"name":"bbbb","location":{"lat":38.0368,"lon":114.5603}}
{"create":{"_index": "products", "_id": "60"}}
{"name":"cccc","location":{"lat":38.0153,"lon":114.5475}}
{"create":{"_index": "products", "_id": "61"}}
{"name":"dddd)","location":{"lat":38.0365,"lon":114.5444}}
{"create":{"_index": "products", "_id": "62"}}
{"name":"eeee","location":{"lat":38.0240,"lon":114.5473}}
{"create":{"_index": "products", "_id": "64"}}
{"name":"ffff","location":{"lat":38.0241,"lon":114.5291}}
GET _search
{
"query": {
"bool": {
"must": [
{ "term": { "_id": "59" } }
],
"filter": [
{ "exists": { "field": "location" } }
]
}
},
"sort": [
{
"_geo_distance": {
"location": [
114.5473,
38.0240
],
"unit": "km",
"order": "asc",
"mode": "min",
"ignore_unmapped": true,
"distance_type": "arc"
}
}
],
"size": 20
}
@gongwalker Thank you for you feedback. Both OS 3.0 and the main branch have been tested on my end(mac m1) and no errors were threw. Could you please provide a more detailed exception stack and environment configuration?
my environment docker Container opensearchproject/opensearch:3.0.0
You can import the following test script to reproduce in opensearch-dashboards.
https://github.com/opensearch-project/OpenSearch/issues/18420 This is the same bug.
Interesting. Since you were able to reproduce it, and I am working on bug #18420, I can try what you did. Thank you!
@gongwalker I know this was a while ago, but since you had the issue with 3.0.0, this is my configuration for docker-compose.yml.
services:
opensearch-node1:
image: opensearchproject/opensearch:3.0.0
container_name: opensearch-node1
environment:
- cluster.name=opensearch-cluster # Name the cluster
- node.name=opensearch-node1 # Name the node that will run in this container
- cluster.initial_cluster_manager_nodes=opensearch-node1 # Nodes eligibile to serve as cluster manager
- bootstrap.memory_lock=true # Disable JVM heap memory swapping
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
- "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch
- "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin
ulimits:
memlock:
soft: -1 # Set memlock to unlimited (no soft or hard limit)
hard: -1
nofile:
soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
hard: 65536
ports:
- 9200:9200 # REST API
- 9600:9600 # Performance Analyzer
Is that the same for you? It unfortunately did not show the issue on my end.
@ajleong623 Below is my composer.yml file
opensearch:
container_name: "con_os"
build: opensearchproject/opensearch:3.0.0
ports:
- "9200:9200"
- "9300:9300"
environment:
- discovery.type=single-node
- "OPENSEARCH_INITIAL_ADMIN_PASSWORD=ABC_OpenSearch_3_0_0"
- "DISABLE_SECURITY_PLUGIN=true"
volumes:
- ./data/opensearch-data:/usr/share/opensearch/data
my environment docker Container opensearchproject/opensearch:3.0.0
You can import the following test script to reproduce in opensearch-dashboards.
@ajleong623
@gongwalker unfortunately, OpenSearch dashboards is not working on my end for some weird reason. But I did follow that logic when I had been testing it. However, I still have to try it with the file you just provided.
Ok, I actually just tried your file, and is it supposed to be a docker-compose.yml file? Is that the full file you used? Because I think it might be missing a heading. And also, the image looks like it is the value of the build key in the yml mapping when usually the value of the build key is supposed to be the location of the context of the build.
Hi @gongwalker - thanks for reporting this. This looks exactly like https://github.com/opensearch-project/OpenSearch/issues/18420 so I'm closing this one so that we have discussion on fix at a single place.
thank @sandeshkr419 This is the best.