elasticsearch - 为什么我使用not_analyzed字段 'term query'并仍然返回分数?

标签 elasticsearch

我只想在某些“已分析”字段上使用tf-idf得分,并在“未分析”字段上使用“term”来整理首选结果。但是结果却不如我预期。

根据官方文件,不会分析'not_analyzed'字段,我认为这是因为es不会在这些字段上进行得分计算。因此,我想利用这一点来整理我想要的东西,因为我想在特定字段上使用tf-idf分数来进行更多计算,但是当添加术语条件时分数会有所不同。
我尝试了3个步骤:
1.在被分析的 Realm 做“比赛”,那是我想要的分数
2.将not_analyzed字段上的“match”和“term”串联起来,但是返回的分数比第一步高
3.仅对“not_analyzed”字段执行“term”,并返回分数。

下面显示了部分代码,这些是4个数据条目:

数据= {“did”:1,“标题”:“hu la la”,“test”:[“a”,“b”,“c”]}

数据= {“did”:2,“标题”:“hu la”,“test”:[“a”,“b”,“c”]}

数据= {“did”:3,“title”:“hu la la”,“test”:[“a”,“b”]}

数据= {“did”:4,“标题”:“la la”,“test”:[“a”,“b”,“c”]}}

mappings = {
    "properties": {
        "did": {"type": "long", "index": "not_analyzed"},
        "title": {"type": "string", "index": "analyzed"},
        "test": {"type": "string", "index": "not_analyzed"},
    }
}
curl -X GET http://localhost:9200/test7/_search?pretty=true -d '
{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "title": "la"
                    }
                }
            ]
        }
    }
}
'

热门之一是
{
      "_index" : "test7",
      "_type" : "default",
      "_id" : "AWoRGrIx5vn17yswf0rR",
      "_score" : 0.4203996,
      "_source" : {
        "did" : 1,
        "test" : [ "a", "b", "c" ],
        "title" : "hu la la"
      }

但是当我加上术语
{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "title": "la"
                    }
                },
                {
                    "term": {
                        "test": "a"
                    }
                }
            ]
        }
    }
}
'

它的分数改变了!
{
      "_index" : "test7",
      "_type" : "default",
      "_id" : "AWoRGrIx5vn17yswf0rR",
      "_score" : 0.7176671,
      "_source" : {
        "did" : 1,
        "test" : [ "a", "b", "c" ],
        "title" : "hu la la"
      }

最佳答案

您应该使用filter查询来过滤出结果,这不会影响得分。

例:

 {
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "title": "la"
                    }
                }               
            ],
            "filter": [
                 {
                    "term": {
                        "test": "a"
                    }
                }
            ]
        }
    }
}

关于elasticsearch - 为什么我使用not_analyzed字段 'term query'并仍然返回分数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55650104/

相关文章:

elasticsearch - 更改ElasticSearch响应json的结构

c# - 使用带有多个参数的NEST进行 Elasticsearch

json - 从单个输入生成多个JQ输出文档,修改每个结果

java - elasticsearch 6.3.2 的 NestedSortBuilder 使用示例

elasticsearch - 如果多个匹配,如何 Elasticsearch “NOT”增加分数

testing - 检查Elasticsearch是否已经完成索引

elasticsearch - 如果搜索字符串比搜索字段长,则文档不匹配

elasticsearch - 使ElasticSearch显示上下文

elasticsearch - 如何使用官方的 docker elasticsearch 容器?

elasticsearch - elasticsearch部署在kubernetes上需要持久化存储吗?