当我通过curl运行时它也会显示正确的结果和统计方面,但是通过java api它将无法显示正确的结果
curl http://localhost:9200/Data/my_data/_search?pretty=true -d '{
"fields" : ["price","total"],
"query" : {
"filtered": {
"query":{
"bool": {
"must": [
{"term" : { "empId" : "1" }},
{
"range": {
"datetime" : {"gte" : "2005-12-23T23:10:52Z", "lte" : "2005-12-23T23:10:56Z" }}
},
{
"range": {
"price" : {"gt" : 0 }}
},
{
"range": {
"total" : {"gt" : 0 }}
}
]
}
}
}
},
"facets" : {
"stat1" : {
"statistical" : {
"field" : "price"
}
}
}
}'
以下是我的java代码:
QueryBuilder qb2 = boolQuery()
.must(termQuery("empId", 1))
.must(rangeQuery("price").gt(0))
.must(rangeQuery("total").gt(0))
.must(rangeQuery("datetime").gte("2005-12-23T23:10:52Z").lte("2005-12-23T23:10:56Z"));
SearchResponse respStats = client.prepareSearch(indexName)
.setTypes(indexType)
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(QueryBuilders.filteredQuery(qb2 ,null))
.addFields("empId","price","datetime")
.addFacet(statisticalFacet("FacetCountStats").field("price"))
.setFrom(0)
.setExplain(false)
.execute()
.actionGet();
但它显示我不想要的零价格和总价值。
提前致谢。
答案 0 :(得分:0)
只是想知道termQuery("empId", 1)
不应该是termQuery("empId", "1")
?