javaelasticsearchgeometrygeospatialelasticsearch-5

Elasticsearch geo search strange behavior


A few days ago I faced with the strange behavior of geo search in Elasticsearch.

I use AWS-managed ES v5.5 over the REST interface.

Context: 200k objects with location info represented as the point only. Geo search is used to find the points within multiple polygons. They are shown on the image below. Coordinates were extracted from the final request to the ES. [![polygons][1]][1] [1]: https://i.sstatic.net/gIN26.jpg

The request is built using the official Java High-level REST client. The request query will be attached below.

I want to search for all objects within at least one polygon. Here is the query (real field names and values were replaced by stub, Except location and locationPoint.coordinates)

{
  "size" : 20,
  "query" : {
    "constant_score" : {
      "filter" : {
        "bool" : {
          "must" : [
            {
              "terms" : {
                "field1" : [
                  "a",
                  "b",
                  "c",
                  "d",
                  "e",
                  "f"
                ],
                "boost" : 1.0
              }
            },
            {
              "term" : {
                "field2" : {
                  "value" : "q",
                  "boost" : 1.0
                }
              }
            },
            {
              "range" : {
                "field3" : {
                  "from" : "10",
                  "to" : null,
                  "include_lower" : true,
                  "include_upper" : true,
                  "boost" : 1.0
                }
              }
            },
            {
              "range" : {
                "field4" : {
                  "from" : "10",
                  "to" : null,
                  "include_lower" : true,
                  "include_upper" : true,
                  "boost" : 1.0
                }
              }
            },
            {
              "geo_shape" : {
                "location" : {
                  "shape" : {
                    "type" : "geometrycollection",
                    "geometries" : [
                      {
                        "type" : "multipolygon",
                        "orientation" : "right",
                        "coordinates" : [
                          [
                            // coords here
                          ]
                        ]
                      },
                      {
                        "type" : "polygon",
                        "orientation" : "right",
                        "coordinates" : [
                          [
                            // coords here
                          ]
                        ]
                      },
                      {
                        "type" : "polygon",
                        "orientation" : "right",
                        "coordinates" : [
                          [
                            // coords here
                          ]
                        ]
                      },
                      {
                        "type" : "polygon",
                        "orientation" : "right",
                        "coordinates" : [
                          [
                            // coords here
                          ]
                        ]
                      }
                    ]
                  },
                  "relation" : "intersects"
                },
                "ignore_unmapped" : false,
                "boost" : 1.0
              }
            }
          ]
        }
      },
      "boost" : 1.0
    }
  },
  "_source" : {
    "includes" : [
      "field1",
      "field2",
      "field3",
      "field4",
      "field8"
    ],
    "excludes" : [ ]
  },
  "sort" : [
    {
      "field1" : {
        "order" : "desc"
      }
    }
  ],
  "aggregations" : {
    "agg1" : {
      "terms" : {
        "field" : "field1",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "agg2" : {
      "terms" : {
        "field" : "field2",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "agg3" : {
      "terms" : {
        "field" : "field3",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "agg4" : {
      "terms" : {
        "field" : "field4",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "agg5" : {
      "terms" : {
        "field" : "field5",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "agg6" : {
      "terms" : {
        "field" : "field6",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "agg7" : {
      "terms" : {
        "field" : "field7",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "agg8" : {
      "terms" : {
        "field" : "field8",
        "size" : 10000,
        "min_doc_count" : 1,
        "shard_min_doc_count" : 0,
        "show_term_doc_count_error" : false,
        "order" : [
          {
            "_count" : "desc"
          },
          {
            "_term" : "asc"
          }
        ]
      }
    },
    "map_center" : {
      "geo_centroid" : {
        "field" : "locationPoint.coordinates"
      }
    },
    "map_bound" : {
      "geo_bounds" : {
        "field" : "locationPoint.coordinates",
        "wrap_longitude" : true
      }
    }
  }
}

Note, that field location is mapped as geo_shape and field location.coordinates is mapped as geo_point.

The problem is next. The results (hits count) of different requests are presented below.

#  Polygons                              Hits count

1) 1,2,3,4                               5565

2) 1                                     4897

3) 3,4                                   75

4) 2                                     9

5) 1,3,4                                 5543

6) 1,2                                   5466

7) 2,3,4                                 84

So, adding results of 1st polygon with 2,3,4 polygons the result doesn't make sense.

For example, #1 != #2 + #7, also #1 != #5 + #4, but #7 == #4 + #3

I cannot understand whether it is the issue in this request or expected behavior or even bug in ES.

Have anyone experienced same thing with ES?

Thanks!


Solution

  • After a short conversation with Elasticsearch team member, the only thing they can highlight at the moment is the build hash of AWS-managed solution which is not the same as original ones.

    Since we do not know what is changed exactly, the issue has to be reproduced on original engine before support will dig deeper.