我正在尝试使用类似于此的 Elasticsearch 的 Java RestHighLevelClient 生成查询:
GET /field_search/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"ENTRY_ID": "ttttt"
}
},
{
"match": {
"MODULE_ID": "xxxxx"
}
},
{
"match": {
"COMPANY_ID": "22244"
}
},
{
"match": {
"DELETED": false
}
}
]
}
}
}
这是我用来生成它的代码
BoolQueryBuilder boolQueryBuilder1 = new BoolQueryBuilder();
boolQueryBuilder1.must().add(QueryBuilders.matchQuery("MODULE_ID", moduleId));
boolQueryBuilder1.must().add(QueryBuilders.matchQuery("COMPANY_ID", companyId));
........
我已经跳过了它的一部分以保持它的小。但我使用 BoolQueryBuilder ,它生成的查询是这样的:
{
"query": {
"bool" : {
"must" : [
{
"match" : {
"MODULE_ID" : {
"query" : "xxxxx",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : false,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"boost" : 1.0
}
}
},
{
"match" : {
"COMPANY_ID" : {
"query" : "22244",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : false,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"boost" : 1.0
}
}
},
{
"match" : {
"DELETED" : {
"query" : false,
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : false,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"boost" : 1.0
}
}
},
{
"match" : {
"ENTRY_ID" : {
"query" : ttttt,
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : false,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}
它在查询中添加了额外的东西。使用上面的普通查询,我的结果正确返回,但是使用 java 生成的查询,我的结果没有,所以我如何使用 Java 客户端构建相同的查询?