Nested object type and join:false and geo_shape


(bants) #1

Hi All,

I would like to be able to search against documents using a geo_shape
filter where the geojson is a nested subdocument and only retrieve the 1
sub document that matched the geographical filter (not the whole document).
I think the docs (specifically nested object type and nested query/filter
docs) state this is possible using join:false. For some reason I can't get
it to work though and I'm convinced its a user error or lack of
understanding.

On ES 90.5 and below is a worked example.

Can someone point me in the right direction please?

Thanks

Clear the deck and create a new index

curl -XDELETE http://localhost:9200/test

{"ok":true,"acknowledged":true}

curl -XPUT http://localhost:9200/test

{"ok":true,"acknowledged":true}

Set a new mapping for the testtype

curl -XPUT http://localhost:9200/test/testtype/_mapping -d '{"testtype":
{"properties": {"entities": {"type": "nested", "properties": {"geometry":
{"tree": "quadtree", "type": "geo_shape","precision": "10m"}}}}}}'
{"ok":true,"acknowledged":true}

Index a new document

curl -XPUT http://localhost:9200/test/testtype/doc1 -d '{"id" : "doc1",
"entities": [{"geometry": {"type" : "Point", "coordinates": [0.0, 0.0]}},
{"geometry": {"type" : "Point", "coordinates": [180.0, 90.0]}}]}'

Query WITH join:false

curl -XGET http://localhost:9200/test/testtype/_search -d '{"query":
{"filtered": {"filter": {"nested" : {"path" : "entities", "join":false,
"filter" : {"geo_shape": {"entities.geometry": {"shape": {"type":
"envelope","coordinates": [[-10.0, 10.0],[10.0, -10.0]]}}}}}},"query":
{"match_all": {}}}}}'

{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

Query WITHour join:false

curl -XGET http://localhost:9200/test/testtype/_search -d '{"query":
{"filtered": {"filter": {"nested" : {"path" : "entities", "filter" :
{"geo_shape": {"entities.geometry": {"shape": {"type":
"envelope","coordinates": [[-10.0, 10.0],[10.0, -10.0]]}}}}}},"query":
{"match_all": {}}}}}'

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"test","_type":"testtype","_id":"doc1","_score":1.0,
"_source" : {"id" : "doc1", "entities": [{"geometry": {"type" : "Point",
"coordinates": [0.0, 0.0]}}, {"geometry": {"type" : "Point", "coordinates":
[180.0, 90.0]}}]}}]}}

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/87ea2d52-66e1-4418-917a-b9b8d720cb0a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(horse.badorties.ny) #2

Hello,

I am trying to achieve something very similar, where a nested filter is
applied on a nested document and I only want the sub doc and not the root
in the hit source. Setting the filter's 'join' to false always returns 0
hits. Did you find a resolution?

Thank you!

On Monday, February 10, 2014 3:09:48 PM UTC-5, bants wrote:

Hi All,

I would like to be able to search against documents using a geo_shape
filter where the geojson is a nested subdocument and only retrieve the 1
sub document that matched the geographical filter (not the whole document).
I think the docs (specifically nested object type and nested query/filter
docs) state this is possible using join:false. For some reason I can't get
it to work though and I'm convinced its a user error or lack of
understanding.

On ES 90.5 and below is a worked example.

Can someone point me in the right direction please?

Thanks

Clear the deck and create a new index

curl -XDELETE http://localhost:9200/test

{"ok":true,"acknowledged":true}

curl -XPUT http://localhost:9200/test

{"ok":true,"acknowledged":true}

Set a new mapping for the testtype

curl -XPUT http://localhost:9200/test/testtype/_mapping -d '{"testtype":
{"properties": {"entities": {"type": "nested", "properties": {"geometry":
{"tree": "quadtree", "type": "geo_shape","precision": "10m"}}}}}}'
{"ok":true,"acknowledged":true}

Index a new document

curl -XPUT http://localhost:9200/test/testtype/doc1 -d '{"id" : "doc1",
"entities": [{"geometry": {"type" : "Point", "coordinates": [0.0, 0.0]}},
{"geometry": {"type" : "Point", "coordinates": [180.0, 90.0]}}]}'

Query WITH join:false

curl -XGET http://localhost:9200/test/testtype/_search -d '{"query":
{"filtered": {"filter": {"nested" : {"path" : "entities", "join":false,
"filter" : {"geo_shape": {"entities.geometry": {"shape": {"type":
"envelope","coordinates": [[-10.0, 10.0],[10.0, -10.0]]}}}}}},"query":
{"match_all": {}}}}}'

{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

Query WITHour join:false

curl -XGET http://localhost:9200/test/testtype/_search -d '{"query":
{"filtered": {"filter": {"nested" : {"path" : "entities", "filter" :
{"geo_shape": {"entities.geometry": {"shape": {"type":
"envelope","coordinates": [[-10.0, 10.0],[10.0, -10.0]]}}}}}},"query":
{"match_all": {}}}}}'

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"test","_type":"testtype","_id":"doc1","_score":1.0,
"_source" : {"id" : "doc1", "entities": [{"geometry": {"type" : "Point",
"coordinates": [0.0, 0.0]}}, {"geometry": {"type" : "Point", "coordinates":
[180.0, 90.0]}}]}}]}}

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3209ffa9-bf61-402e-a21a-571deaf34fad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(bants) #3

Hey - no, sorry I didn't ever get a response.

Picking up this work over the next couple of times so I'll see if I come up
with anything.

On Thursday, May 29, 2014 2:16:07 PM UTC+1, horse.bad...@gmail.com wrote:

Hello,

I am trying to achieve something very similar, where a nested filter is
applied on a nested document and I only want the sub doc and not the root
in the hit source. Setting the filter's 'join' to false always returns 0
hits. Did you find a resolution?

Thank you!

On Monday, February 10, 2014 3:09:48 PM UTC-5, bants wrote:

Hi All,

I would like to be able to search against documents using a geo_shape
filter where the geojson is a nested subdocument and only retrieve the 1
sub document that matched the geographical filter (not the whole document).
I think the docs (specifically nested object type and nested query/filter
docs) state this is possible using join:false. For some reason I can't get
it to work though and I'm convinced its a user error or lack of
understanding.

On ES 90.5 and below is a worked example.

Can someone point me in the right direction please?

Thanks

Clear the deck and create a new index

curl -XDELETE http://localhost:9200/test

{"ok":true,"acknowledged":true}

curl -XPUT http://localhost:9200/test

{"ok":true,"acknowledged":true}

Set a new mapping for the testtype

curl -XPUT http://localhost:9200/test/testtype/_mapping -d '{"testtype":
{"properties": {"entities": {"type": "nested", "properties": {"geometry":
{"tree": "quadtree", "type": "geo_shape","precision": "10m"}}}}}}'
{"ok":true,"acknowledged":true}

Index a new document

curl -XPUT http://localhost:9200/test/testtype/doc1 -d '{"id" : "doc1",
"entities": [{"geometry": {"type" : "Point", "coordinates": [0.0, 0.0]}},
{"geometry": {"type" : "Point", "coordinates": [180.0, 90.0]}}]}'

Query WITH join:false

curl -XGET http://localhost:9200/test/testtype/_search -d '{"query":
{"filtered": {"filter": {"nested" : {"path" : "entities", "join":false,
"filter" : {"geo_shape": {"entities.geometry": {"shape": {"type":
"envelope","coordinates": [[-10.0, 10.0],[10.0, -10.0]]}}}}}},"query":
{"match_all": {}}}}}'

{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

Query WITHour join:false

curl -XGET http://localhost:9200/test/testtype/_search -d '{"query":
{"filtered": {"filter": {"nested" : {"path" : "entities", "filter" :
{"geo_shape": {"entities.geometry": {"shape": {"type":
"envelope","coordinates": [[-10.0, 10.0],[10.0, -10.0]]}}}}}},"query":
{"match_all": {}}}}}'

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"test","_type":"testtype","_id":"doc1","_score":1.0,
"_source" : {"id" : "doc1", "entities": [{"geometry": {"type" : "Point",
"coordinates": [0.0, 0.0]}}, {"geometry": {"type" : "Point", "coordinates":
[180.0, 90.0]}}]}}]}}

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1ab3c47b-32c8-4905-b524-09e9692c8327%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4