弹性搜索:使用弹性搜索生成弹性搜索查询 API
Elastic Search: Generating Elastic Search query using Elastic search API
我想知道硬编码查询和通过 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();
elasticsearch spring 数据库生成的查询具有 current documentation of the spring-data-elasticsearch and it really depends on what elasticsearch version you are running. If you really want to use a pure query created by you, you can take a look at the Query
annotation here
中记录的默认值
这里有一些关于在生成的查询中添加的额外属性的有用文档:
我想知道硬编码查询和通过 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();
elasticsearch spring 数据库生成的查询具有 current documentation of the spring-data-elasticsearch and it really depends on what elasticsearch version you are running. If you really want to use a pure query created by you, you can take a look at the Query
annotation here
这里有一些关于在生成的查询中添加的额外属性的有用文档: