2015-10-02 65 views
0

我使用ELasticsearch和Meteor.js與npm/elasticsearch插件一起使用ES與Meteor。 這裏是我的查詢:Elasticsearch搜索解析異常但返回結果

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)發送和接收的除外答案,但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字段類型。

這裏是我的映射revelant部分:

{ 
      '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類型?

+0

你能告訴你發送查詢到的網址是什麼? – Val

+0

它不是一個URL。我使用NPM Elasticsearch,一個用於node.js的ES api包裝器,所以它只是'esClient.search(搜索)' – dagatsoin

+0

你可以在'search'選項哈希中顯示你有什麼設置嗎? – Val

回答

1

您需要將您的查詢發送到包含trace類型文檔的索引。如果您將查詢發送到根端點/(默認值,如果未指定),則將查詢所有索引。在你的情況下,它失敗,因爲.marvel-2015.10.02索引沒有任何geo_point字段loc.coordinates

所以,你的呼叫需要看起來像這樣:

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

ho。完善。感謝Val :) – dagatsoin