node.js - Elasticsearch搜索解析异常,但返回结果

标签 node.js meteor elasticsearch

我将ELasticsearch和Meteor.js与npm / elasticsearch插件一起使用,将ES与Meteor一起使用。
这是我的查询:

search = {
"body": {
  "aggs": {
    "traces": {
      "filter": {
        "and": [
          {
            "range": {
              "date": {
                "gte": "2015-01-31T23:00:00.000Z",
                "lte": "2015-10-02T21:59:59.000Z"
              }
            }
          },
          {
            "geo_bounding_box": {
              "loc.coordinates": {
                "top_left": {
                  "lat": 51.767839887322154,
                  "lon": -9.404296875
                },
                "bottom_right": {
                  "lat": 40.96330795307353,
                  "lon": 14.326171874999998
                }
              }
            }
          },
          {
            "or": [
              {
                "and": [
                  {
                    "term": {
                      "geoip": false
                    }
                  },
                  {
                    "term": {
                      "trackerId": "RG-000000010-1"
                    }
                  }
                ]
              }
            ]
          }
        ]
      },
      "aggs": {
        "trackerId": {
          "terms": {
            "field": "trackerId",
            "size": 0
          },
          "aggs": {
            "heatmap": {
              "geohash_grid": {
                "field": "loc.coordinates",
                "precision": 6
              }
            }
          }
        }
      }
    }
  }
 }
}

我用esClient.search(search)发送它并收到异常(exception)的答案,但是ES抛出此错误:
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:735)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:560)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:532)
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:294)
    at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
    at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
    at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.index.query.QueryParsingException: [.marvel-2015.10.02]
**failed to find geo_point field [loc.coordinates]**
    at org.elasticsearch.index.query.GeoBoundingBoxFilterParser.parse(GeoBoundingBoxFilterParser.java:173)
    at org.elasticsearch.index.query.QueryParseContext.executeFilterParser(QueryParseContext.java:368)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:349)
    at org.elasticsearch.index.query.AndFilterParser.parse(AndFilterParser.java:65)
    at org.elasticsearch.index.query.QueryParseContext.executeFilterParser(QueryParseContext.java:368)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:349)
    at org.elasticsearch.index.query.IndexQueryParserService.parseInnerFilter(IndexQueryParserService.java:295)
    at org.elasticsearch.search.aggregations.bucket.filter.FilterParser.parse(FilterParser.java:42)
    at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:148)
    at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:78)
    at org.elasticsearch.search.aggregations.AggregationParseElement.parse(AggregationParseElement.java:60)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:719)

显然,它找不到geo_point字段类型。

这是我映射的启示部分:
{
            'trace': {
                'properties': {
                    'loc': {
                        'type': 'object',
                        'properties': {
                            'type': {
                                'type': 'string'
                            },
                            'coordinates':{
                                'type': 'geo_point',
                                'geohash':true,
                                'geohash_prefix':true,
                                'lat_lon':true,
                                'fielddata' : {
                                    'format' : 'compressed',
                                    'precision' : '1cm'
                                }
                            }
                        }
                    }
    ...

那么为什么找不到geo_point类型呢?

最佳答案

您需要将查询发送到包含trace类型文档的索引。如果将查询发送到根端点/(如果未指定,则为默认值),则将查询所有索引。在您的情况下,此操作失败,因为.marvel-2015.10.02索引没有名为geo_pointloc.coordinates字段。

因此,您的通话应如下所示:

var search = {
    index: "your_index",             <--- add this
    body: {...}
};
esClient.search(search);

关于node.js - Elasticsearch搜索解析异常,但返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32904556/

相关文章:

javascript - 面向个人用户的带有 Node.js 和 Socket.io 的 Pubsub

javascript - XMLHttpRequest 无法加载请求的资源上不存在 'Access-Control-Allow-Origin' header 。起源 'http://localhost:3000' 谷歌地图

javascript - Node-Promisify 一个包含循环的函数

meteor - 根据另一个集合中特定文档的存在,将集合中的文档发布到 meteor 客户端(publish-with-relations)

ElasticSearch 查询查找两个查询的交集

elasticsearch - Elasticsearch从快照还原单个索引

node.js - 使用 node-markdown 模块渲染 markdown 时输出不一致

javascript - 从 node.js 服务器下载文件

javascript - 我应该使用助手还是 jQuery 设置 Meteor 导航模板?

elasticsearch - 嵌套术语聚合的存储桶路径应该是什么?