我在0.90.5版本上使用ElasticSearch。 我尝试使用像这样的GeoShapeQuery来限制我使用QueryStringQuery解析的查询:
public SearchResponse search(final String queryString, final Rectangle bbox){
final QueryBuilder queryA = QueryBuilders.queryString(queryString);
final QueryBuilder queryB = QueryBuilders.geoShapeQuery(GEO_FIELD_NAME, bbox);
final QueryBuilder query = QueryBuilders.boolQuery()
.must(queryA)
.must(queryB);
return client.prepareSearch(INDEX_NAME)
.setQuery(query)
...
}
但是,如果要构建查询,则抛出以下异常:
org.elasticsearch.index.query.QueryBuilderException: Failed to build query
at org.elasticsearch.index.query.BaseQueryBuilder.toString(BaseQueryBuilder.java:42)
at org.bitmash.data.EsDatabase.search(EsDatabase.java:279)
at org.agopt.server.GisServer.search(GisServer.java:270)
at org.bitmash.gis.protocol.requests.SearchRequest.process(SearchRequest.java:40)
at org.bitmash.gis.protocol.requests.SearchRequest.process(SearchRequest.java:21)
at network.tcp.binary.BinaryServerSide$1.run(BinaryServerSide.java:72)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.elasticsearch.common.jackson.core.JsonGenerationException: Current context not an ARRAY but OBJECT
at org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError(GeneratorBase.java:444)
at org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.writeEndArray(UTF8JsonGenerator.java:229)
at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeEndArray(JsonXContentGenerator.java:59)
at org.elasticsearch.common.xcontent.XContentBuilder.endArray(XContentBuilder.java:227)
at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:182)
at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:149)
at org.elasticsearch.index.query.BaseQueryBuilder.toXContent(BaseQueryBuilder.java:65)
at org.elasticsearch.index.query.BaseQueryBuilder.toString(BaseQueryBuilder.java:39)
... 8 more
我错过了什么吗? 是否有可能使用BoolQuery组合任何两个查询?
感谢您的帮助!
答案 0 :(得分:0)