代码之家  ›  专栏  ›  技术社区  ›  Artem Vereschaka

Elasticsearch地理搜索奇怪的行为

  •  0
  • Artem Vereschaka  · 技术社区  · 7 年前

    几天前,我在Elasticsearch中遇到了地理搜索的奇怪行为。

    我使用AWS管理的ES 5.5,明显优于REST接口。

    假设我们有200k个对象,其位置信息仅表示为点。我使用地理搜索在多个多边形中查找点。它们如下图所示。坐标是从ES的最终请求中提取的。 polygons 该请求是使用官方Java高级REST客户端构建的。请求查询将附在下面。

    我想搜索至少 多边形 这是查询(实数字段名称和值被存根替换, 除了 位置和定位点。坐标)

    {
      "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
          }
        }
      }
    }
    

    笔记 ,该字段 地方 映射为 geo_形状 和字段 地方协调 映射为 geo\u点 .

    所以问题是下一个。 下面给出了请求的结果(点击次数)。只有多边形在变化。

    #  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
    

    因此,如果我将多边形1的结果与2,3,4个多边形相加,我将无法获得完整请求中的数字。

    例如 #1 != #2 + #7 而且 #1 != #5 + #4 , 但是 #7 == #4 + #3

    我无法理解这是这个请求中的问题还是预期的行为,甚至是ES中的bug。

    有谁能帮我理解这种ES行为的逻辑或指出解决方案吗?

    谢谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Artem Vereschaka    7 年前

    在与Elasticsearch团队成员进行简短对话后,我们来到AWS。 AWS和纯ES的构建哈希不相等,因此,ES由AWS团队修改,我们不知道确切的变化。在发布的问题中可能会有一些更改影响搜索。 在我们继续对话之前,需要在纯ES集群上重现这种行为。