我想知道硬线查询和通过 API 生成的查询之间的区别?我正在使用弹性搜索 API 来构建查询。我期望的结果查询具有以下格式。
{
"query": {
"bool": {
"must": [
{"match": {
"model": "IBC"
}
},{"match": {
"company.name": "Samsung"
}
}
]
}
}
}
但是我使用 ElasticSearch 查询构建器 API 获得的输出格式如下。我观察到,对于小型数据集,这两个查询获得的结果完全相同。我不确定它对大型数据集的表现如何。
{
"size": 100,
"query": {
"bool": {
"must": [
{
"match": {
"company.name": {
"query": "Samsung",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1.0
}
}
},
{
"match": {
"model": {
"query": "IBC",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1.0
}
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
}
我为生成查询而编写的代码:
Map<String,String> parametersMap = new HashMap<String,String>();
parametersMap.put("model","IBC");
parametersMap.put("company.name","Samsung");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
for(String key: parametersMap){
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(key,parametersMap.get(key);
boolQueryBuilder = boolQueryBuilder.must(matchQueryBuilder);
}
searchSourceBuilder.size(100).query(boolQueryBuilder);
String result = searchSourceBuilder.toString();