elasticsearch,mongoosastic,Node.js,elasticsearch,Mongoosastic" /> elasticsearch,mongoosastic,Node.js,elasticsearch,Mongoosastic" />

Node.js 如何在elasticsearch中对地理坐标应用过滤器?

Node.js 如何在elasticsearch中对地理坐标应用过滤器?,node.js,elasticsearch,mongoosastic,Node.js,elasticsearch,Mongoosastic,我正在使用elasticsearch和Mongoostic npm模块。我正在尝试对具有以下模型结构的地理坐标应用过滤器 geoLocation: { type: { type: String, default: 'Point' }, coordinates: [Number] //orders should be lat,lng } 其映射如下所示 { "events": { "settings": {

我正在使用elasticsearch和Mongoostic 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[未能执行阶段[query], 所有碎片都失败;碎片失败{[CDHdgtJnTbeu8tl2mDfllg][events][0]: SearchParseException[[events][0]:来自[-1],大小[-1]:分析失败 [未能分析源代码]

curl-XGET localhost:9200/events

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

我的问题有了答案

映射

PUT/geo_测试

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

POST/geo_测试/类型_测试/搜索

{
   "query": {
      "filtered": {
         "filter": {
            "nested": {
               "path": "geoLocation",
               "query": {
                  "filtered": {
                     "filter": {
                        "geo_distance": {
                           "distance": 5,
                           "distance_unit": "km",
                           "geoLocation.coordinates": {
                              "lat": 41.12,
                              "lon": -71.34
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

在您的查询中,只需使用
“geoLocation”
而不是
“geoLocation.coordinates”
就可以了。@Val--让我来看看try@Val--它仍然不起作用。实际上,没有在已存档的地理位置上创建索引。您现在遇到了什么错误?@val:与上面相同的错误