Elasticsearch按照相关性得分的顺序搜索所有文档



我在新闻标题文档的列表中有一个复杂的匹配查询

{
"bool" : {
"should" : [
{
"multi_match" : {
"query" : " Reliance gets shareholders, creditors nod for hiving off O2C business into separate unit - The HinduBillionaire Mukesh Ambani's Reliance Industries Ltd on Friday said it has secured approval of its shareholders and creditors for hiving off its oil-to-chemical (O2C) business into a separate unit.",
"fields" : [
"article.description^1.0",
"article.title^1.0"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"fuzzy_transpositions" : true,
"boost" : 3.0
}
},
{
"match" : {
"article.author" : {
"query" : " PTI",
"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" : {
"article.source.name" : {
"query" : " The Hindu",
"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
}
}

问题是弹性搜索只返回相关文档,我想要尽可能多的文档,按照相关分数的递减顺序。退回所有文件是可以的,但订购应该按照这个顺序。我找不到更好的方法从新闻库中弹性搜索5-10个文档,而我有1000篇文章。

默认情况下,弹性搜索只返回10个文档。如果要返回10个以上的文档,则需要设置size参数。

修改后的查询将是

{
"size": 1000,         // note this
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": " Reliance gets shareholders, creditors nod for hiving off O2C business into separate unit - The HinduBillionaire Mukesh Ambani's Reliance Industries Ltd on Friday said it has secured approval of its shareholders and creditors for hiving off its oil-to-chemical (O2C) business into a separate unit.",
"fields": [
"article.description^1.0",
"article.title^1.0"
],
"type": "best_fields",
"operator": "OR",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 3.0
}
},
{
"match": {
"article.author": {
"query": " PTI",
"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": {
"article.source.name": {
"query": " The Hindu",
"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
}
}
}

相关内容

最新更新