Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 根据Elasticsearch中的最佳字段匹配进行搜索_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Search_Full Text Search - Fatal编程技术网 elasticsearch 根据Elasticsearch中的最佳字段匹配进行搜索,elasticsearch,search,full-text-search,elasticsearch,Search,Full Text Search" /> elasticsearch 根据Elasticsearch中的最佳字段匹配进行搜索,elasticsearch,search,full-text-search,elasticsearch,Search,Full Text Search" />

elasticsearch 根据Elasticsearch中的最佳字段匹配进行搜索

elasticsearch 根据Elasticsearch中的最佳字段匹配进行搜索,elasticsearch,search,full-text-search,elasticsearch,Search,Full Text Search,在下面的文档中搜索“foo bar”将获得name*的累积结果,但我想获得最匹配字段的分数(即name1score) 查询例如: { "query": { "filtered": { "query": { "bool": { "should": [{ "match": { "name1": { "query": "foo bar"

在下面的文档中搜索“foo bar”将获得
name*
的累积结果,但我想获得最匹配字段的分数(即
name1
score)

查询例如:

{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [{
            "match": {
              "name1": {
                "query": "foo bar"
              }
            }
          }, {
            "match": {
              "name2": {
                "query": "foo bar"
              }
            }
          }, {
            "match": {
              "name3": {
                "query": "foo bar"
              }
            }
          }]
        }
      }
    }
  }
}
使用Elasticsearch 2.4结合所有子查询的得分。从文档:

bool查询采用的匹配次数越多越好的方法,因此分数越高 从每个匹配的must或should子句将一起添加到 提供每个文件的最终分数

对于您的情况,您希望使用另一个加入查询:

一种查询,用于生成由其 子查询,并为每个文档的 由任何子查询生成的文档,加上一个中断连接 任何其他匹配子查询的增量

例如:

{
  "query": {
    "dis_max": {
      "queries": [
        {
          "match": {
            "name1": {
              "query": "foo bar"
            }
          }
        },
        {
          "match": {
            "name2": {
              "query": "foo bar"
            }
          }
        },
        {
          "match": {
            "name3": {
              "query": "foo bar"
            }
          }
        }
      ]
    }
  }
}
*注意,我是在ES6上写的,它不再有
过滤的
查询,但我希望您能理解要点:)


希望这有帮助

可能要共享您的查询?:)@拜伦沃巴赫编辑了这篇文章
{
  "query": {
    "dis_max": {
      "queries": [
        {
          "match": {
            "name1": {
              "query": "foo bar"
            }
          }
        },
        {
          "match": {
            "name2": {
              "query": "foo bar"
            }
          }
        },
        {
          "match": {
            "name3": {
              "query": "foo bar"
            }
          }
        }
      ]
    }
  }
}