2017-03-23 178 views
0

我想構建這個json使用QueryBuilders但「查詢」鍵是從json丟失,任何人都可以幫助我嗎?查詢爲java客戶端

{ 
    "query": { 
     "bool": { 
      "disable_coord": false, 
      "adjust_pure_negative": true, 
      "boost": 1.0 
     } 
    } 
} 

回答

0

對於query包裹,可以使用SearchSourceBuilderQueryBuilder,也許像:

BoolQueryBuilder must = boolQuery().adjustPureNegative(true).disableCoord(false).boost(1.0f) 
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 
searchSourceBuilder.query(must); 
XContentBuilder xContentBuilder = jsonBuilder(); 
searchSourceBuilder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); 
System.out.println(xContentBuilder.string()); 
+0

{ 「查詢」:{ 「布爾」:{ 「disable_coord」:假的, 「adjust_pure_negative」:真實, 「boost」:1.0}}}在這個JSON的關鍵「查詢」仍然失蹤 –

+0

@NitinChand,對不起誤解,我已經更新了我的答案,希望有幫助 – chengpohi

+0

感謝百萬:) –