Query for geo_bounding_box in nested documents


(Raymond Pendergraph) #1

I am having an issue figuring out how to represent a geo_bounding_box query
for a geo_point field which is located in a nested document. It seems to be
having an issue finding the field in the nested document. I tried leaving
out the nested clause (just using document_b.location in the
geo_bounding_box) too but that did not seem to work either. Here is a
simplified test case of what I am trying to do:

curl -XDELETE localhost:9200/geo_test
echo "Map"
curl -XPUT localhost:9200/geo_test -d '{
"mappings": {
"document_a": {
"properties": {
"name": {"type": "string"},
"document_b": {
"type": "nested",
"properties": {
"location": {
"type": "geo_point",
"lat_lon": "true"
}
}
}
}
}
}
}'
echo
echo "Insert"
curl -XPUT localhost:9200/geo_test/document_a/2 -d '{
"id": 2,
"name": "MyTest",
"document_b": {
"location":{
"lat": 32.9,
"lon": 69.25
}
}
}'
echo
echo "Refresh"
curl -XPOST localhost:9200/geo_test/_refresh
echo
echo "Query"
curl -XPOST "localhost:9200/geo_test/geo_test/_search?pretty=true" -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "document_b",
"query": {
"filtered":{
"query": {"match_all": {}},
"filter": {
"geo_bounding_box" : {
"location" : {
"top_left" : {
"lat" : 32.9,
"lon" : 69.25
},
"bottom_right" : {
"lat" : 33.0,
"lon" : 69.5
}
}
}
}
}
}
}
}
}

  }

}'
echo

The error that I am getting is
nested: QueryParsingException[[geo_test] failed to find geo_point field
[location]]

Any help is greatly appreciated.

Ray

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Alexander Reelsen) #2

Hey,

couple of corrections for your query

curl -XPOST "localhost:9200/geo_test/document_a/_search?pretty=true" -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "document_b",
"filter": {
"geo_bounding_box" : {
"document_b.location" : {
"top_left" : { "lat" : 33.0, "lon" : 69.24 },
"bottom_right" : { "lat" : 32.8, "lon" : 69.5 }
}
}
}
}
}
}
}
}'

Couple of minor corrections I did:

  • Using a nested filter instead of a query
  • Your search in your mail searched only for type geo_test, but you needed
    to search for type document_a
  • your bounding boxes were not correct, it would never have matched (not
    kidding, but I have a small post it at my monitor which kindly shows a neat
    little earth where the lat/long ranges are running at, because I screw it
    up daily :slight_smile:
  • Even if you are inside of a nested filter, you still have to specify the
    full path in the filter (document_b.location instead of location)

Hope this helps!

--Alex

--Alex

On Tue, Nov 5, 2013 at 5:27 PM, Raymond Pendergraph <
raypendergraph@gmail.com> wrote:

I am having an issue figuring out how to represent a geo_bounding_box
query for a geo_point field which is located in a nested document. It seems
to be having an issue finding the field in the nested document. I tried
leaving out the nested clause (just using document_b.location in the
geo_bounding_box) too but that did not seem to work either. Here is a
simplified test case of what I am trying to do:

curl -XDELETE localhost:9200/geo_test
echo "Map"
curl -XPUT localhost:9200/geo_test -d '{
"mappings": {
"document_a": {
"properties": {
"name": {"type": "string"},
"document_b": {
"type": "nested",
"properties": {
"location": {
"type": "geo_point",
"lat_lon": "true"
}
}
}
}
}
}
}'
echo
echo "Insert"
curl -XPUT localhost:9200/geo_test/document_a/2 -d '{
"id": 2,
"name": "MyTest",
"document_b": {
"location":{
"lat": 32.9,
"lon": 69.25
}
}
}'
echo
echo "Refresh"
curl -XPOST localhost:9200/geo_test/_refresh
echo
echo "Query"
curl -XPOST "localhost:9200/geo_test/geo_test/_search?pretty=true" -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "document_b",
"query": {
"filtered":{
"query": {"match_all": {}},
"filter": {
"geo_bounding_box" : {
"location" : {
"top_left" : {
"lat" : 32.9,
"lon" : 69.25
},
"bottom_right" : {
"lat" : 33.0,
"lon" : 69.5
}
}
}
}
}
}
}
}
}

  }

}'
echo

The error that I am getting is
nested: QueryParsingException[[geo_test] failed to find geo_point field
[location]]

Any help is greatly appreciated.

Ray

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #3