ElasticSearch嵌套查询分数

2eafrhcq  于 2022-09-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(171)

我有一个索引:

PUT my_index2
{
  "mappings": {
    "my_type": {
      "properties": {
        "user": {
          "type": "nested" 
        }
      }
    }
  }
}

我有两份文件:

POST my_index2/my_type/
{
  "user": [
    {
      "name": "Alice Don"
    },
    {
      "name": "Smith"
    }
  ]
}

POST my_index2/my_type/
{
  "user": [
    {
      "name": "Alice David"
    }
  ]
}

当我搜索它时:

GET my_index2/_search
{
    "query": {
        "nested" : {
            "path" : "user",

            "query" : {
                "bool" : {
                    "should" : [
                    { "match" : {"user.name" : "Alice"} }
                    ]
                }
            }
        }
    }
}

虽然两个文档都有一个“Alice”,但第一个文档的分数更高。这怎么可能呢?

2vuwiymt

2vuwiymt1#

您的第一个文档的“name”较短,因此在“Query”和“name”之间有更多相同的字符

相关问题