I think this is the key probably because any 1 document will never be in 2 distinct / separate boxes... so there never will be a match, see below.
I tried that but it does not work because any one point is not in both boxes... interesting....
I am not clear on how to do this because when the search executes it executes against a single document at a time and that single document will not be in 2 different disconnected boxes.
1 field like the name is in both but the location for any one document is not in both boxes... so I am not clear on how to do this... I will look at bit more... but I am at a loss at the moment
Here are my current samples
stamford
is in both boxes
armonk
is only in 1 box
# "minimum_should_match" : 1 give both and even armonk
# "minimum_should_match" : 2 does not give either
DELETE /city
PUT /city
{
"mappings": {
"properties": {
"name" : {"type" : "keyword"},
"location": {
"type": "geo_point"
}
}
}
}
POST /city/_doc/
{
"name": "stamford",
"location": [-73.554212, 41.053923]
}
POST /city/_doc
{
"name": "greenwich",
"location": [-74.624998,42.047451]
}
POST /city/_doc
{
"name": "armonk",
"location": [-75.708180,43.126757]
}
POST /city/_doc
{
"name": "stamford",
"location": [-75.718180,43.136757]
}
POST /city/_doc
{
"name": "north stamford",
"location": [-76.572866,44.142307]
}
POST /city/_doc
{
"name": "greenwich2",
"location": [-73.681591,41.098201]
}
POST /city/_doc
{
"name": "rye brook",
"location": [-73.683025,41.017221]
}
# Here is the should but results return for stamford (in both) armonk only 1
# "minimum_should_match" : 1 give both and even armonk
# "minimum_should_match" : 2 does not give either
GET /city/_search
{
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"exists": {
"field": "location"
}
},
{
"term": {
"name": {
"value": "stamford" <!-- test with armonk too
}
}
}
],
"should": [
{
"geo_shape": {
"ignore_unmapped": true,
"location": {
"relation": "INTERSECTS",
"shape": {
"coordinates": [
[
[
-75.15639,
42.35149
],
[
-75.15639,
40.53426
],
[
-72.92849,
40.53426
],
[
-72.92849,
42.35149
],
[
-75.15639,
42.35149
]
]
],
"type": "Polygon"
}
}
}
},
{
"geo_shape": {
"ignore_unmapped": true,
"location": {
"relation": "INTERSECTS",
"shape": {
"type": "Polygon",
"coordinates": [
[
[
-75.80553,
43.20558
],
[
-75.80553,
43.03916
],
[
-75.55147,
43.03916
],
[
-75.55147,
43.20558
],
[
-75.80553,
43.20558
]
]
]
}
}
}
}
],
"minimum_should_match" : 1
}
}
]
}
}
}