我发现了这个很棒的插件,用于在 elasticsearch 中创建基于 geohash 的构面。它似乎在 _head pluing 中工作得很好。我只是不太确定如何从 JavaClient 代码运行它。
我编写了代码来运行匹配查询,但不确定如何向其中添加 geohash 过滤器。
{
"query": {
"match_all": {}
},
"facets": {
"places": {
"geohash": {
"field": "location",
"factor": 0.9
}
}
}
}
我认为以下内容会有所帮助,但无济于事。它抛出
Exception in thread "main" org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed; shardFailures {[IokTP1RuQ520T86dxU345w][easythahr][1]: SearchParseException[[easythahr][1]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][1]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][2]: SearchParseException[[easythahr][2]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][2]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][3]: SearchParseException[[easythahr][3]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][3]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][4]: SearchParseException[[easythahr][4]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][4]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][0]: SearchParseException[[easythahr][0]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][0]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }
XContentBuilder b = jsonBuilder().startObject("places")
.startObject("geoHash")
.field("field", "location")
.field("factor",0.9)
.endObject()
.endObject();
SearchResponse response = client.prepareSearch("easythahr")
.setTypes("com.easytha.Student")
.setQuery(matchQuery)
.setFacets(b)
.setFrom(0)
.setSize(100)
.execute()
.actionGet();