1

我正在使用弹性搜索和 mongoosastic npm 模块。我正在尝试对具有以下模型结构的地理坐标应用过滤器

geoLocation: {
    type: {
      type: String,
      default: 'Point'
    },
    coordinates: [Number] //orders should be lat,lng
  }

映射如下

{
      "events": {
        "settings": {
          "analysis": {
            "filter": {
              "edgeNGram_filter": {
                "type": "edgeNGram",
                "min_gram": 1,
                "max_gram": 50,
                "side": "front"
              }
            },
            "analyzer": {
              "edge_nGram_analyzer": {
                "type": "custom",
                "tokenizer": "edge_ngram_tokenizer",
                "filter": [
                  "lowercase",
                  "asciifolding",
                  "edgeNGram_filter"
                ]
              },
              "whitespace_analyzer": {
                "type": "custom",
                "tokenizer": "whitespace",
                "filter": [
                  "lowercase",
                  "asciifolding"
                ]
              }
            },
            "tokenizer": {
              "edge_ngram_tokenizer": {
                "type": "edgeNGram",
                "min_gram": "1",
                "max_gram": "50",
                "token_chars": [
                  "letter",
                  "digit"
                ]
              }
            }
          }
        },
        "mappings": {
          "event": {
            "_all": {
              "index_analyzer": "nGram_analyzer",
              "search_analyzer": "whitespace_analyzer"
            },
            "properties": {
              "title": {
                "type": "string",
                "index": "not_analyzed"
              },
              "geoLocation": {
                "index": "not_analyzed",
                "type": "geo_point"
              }
            }
          }
        }
      }
    }

询问

{
        "query": {
          "multi_match": {
            "query": "the",
            "fields": ["title", ]
          }
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "200km",
                "geoLocation.coordinates" : {
                    "lat" : 19.007452,
                    "lon" : 72.831556
                }
            }
        }
      }

我无法使用以下模型结构在地理坐标上创建索引,我不明白是否无法使用上述模型结构索引地理坐标,因为在我的情况下,坐标的顺序为 lat,long,我在某处找到elasticsearch期望坐标顺序为long,lat。

错误

错误:SearchPhaseExecutionException[未能执行阶段[查询],所有分片失败;shardFailures {[CDHdgtJnTbeu8tl2mDfllg][events][0]: SearchParseException[[events][0]: from[-1],size[-1]: Parse Failure [Failed to parse source

curl -XGET 本地主机:9200/事件

{
  "events": {
    "aliases": {},
    "mappings": {
      "1": {
        "properties": {
          "location": {
            "type": "double"
          },
          "text": {
            "type": "string"
          }
        }
      },
      "event": {
        "properties": {
          "city": {
            "type": "string"
          },
          "endTime": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "geo_with_lat_lon": {
            "type": "geo_point",
            "lat_lon": true
          },
          "isActive": {
            "type": "boolean"
          },
          "isRecommended": {
            "type": "boolean"
          },
          "location": {
            "type": "string"
          },
          "title": {
            "type": "string"
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1461675012489",
        "uuid": "FT-xVUdPQtyuKFm4J4Rd7g",
        "number_of_replicas": "1",
        "number_of_shards": "5",
        "events": {
          "mappings": {
            "event": {
              "_all": {
                "enabled": "false",
                "search_analyzer": "whitespace_analyzer",
                "index_analyzer": "nGram_analyzer"
              },
              "properties": {
                "geoLocation": {
                  "coordinates": {
                    "type": "geo_shape",
                    "index": "not_analyzed"
                  }
                },
                "location": {
                  "type": "string",
                  "index": "not_analyzed"
                },
                "title": {
                  "type": "string",
                  "index": "not_analyzed"
                },
                "geo_with_lat_lon": {
                  "type": "geo_point",
                  "lat_lon": "true",
                  "index": "not_analyzed"
                }
              }
            }
          },
          "settings": {
            "analysis": {
              "analyzer": {
                "edge_nGram_analyzer": {
                  "type": "custom",
                  "filter": [
                    "lowercase",
                    "asciifolding",
                    "edgeNGram_filter"
                  ],
                  "tokenizer": "edge_ngram_tokenizer"
                },
                "whitespace_analyzer": {
                  "type": "custom",
                  "filter": [
                    "lowercase",
                    "asciifolding"
                  ],
                  "tokenizer": "whitespace"
                }
              },
              "filter": {
                "edgeNGram_filter": {
                  "max_gram": "50",
                  "type": "edgeNGram",
                  "min_gram": "1",
                  "side": "front"
                }
              },
              "tokenizer": {
                "edge_ngram_tokenizer": {
                  "max_gram": "50",
                  "type": "edgeNGram",
                  "min_gram": "1",
                  "token_chars": [
                    "letter",
                    "digit"
                  ]
                }
              }
            }
          }
        },
        "version": {
          "created": "1070099"
        }
      }
    },
    "warmers": {}
  }
}
4

1 回答 1

2

我的问题得到了解决方案

映射

放置 /geo_test

{
   "mappings": {
      "type_test": {
         "properties": {
            "name": {
               "type": "string"
            },
            "geoLocation": {
               "type": "nested",
               "properties": {
                  "coordinates": {
                     "type": "geo_point",
                     "lat_lon": true
                  }
               }
            }
         }
      }
   }
}

询问

发布 /geo_test/type_test/_search

{
   "query": {
      "filtered": {
         "filter": {
            "nested": {
               "path": "geoLocation",
               "query": {
                  "filtered": {
                     "filter": {
                        "geo_distance": {
                           "distance": 5,
                           "distance_unit": "km",
                           "geoLocation.coordinates": {
                              "lat": 41.12,
                              "lon": -71.34
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}
于 2016-04-30T21:29:21.793 回答