在 Elasticsearch 中对同义词进行平均评分

score synonyms equally in Elasticsearch

我们能否在elasticsearch中对原始字符串和同义词进行平均评分。

例如。我将我的同义词文件创建为:

pvt, private

ltd, limited

我使用同义词标记过滤器创建了一个索引。然后我索引了两个文档:

curl -XPOST "http://localhost:9200/test1/test?pretty" -d 
    '{ "entityName" : "ABC International Pvt Ltd"}'

curl -XPOST "http://localhost:9200/test1/test?pretty" -d 
    '{ "entityName" : "ABC International Private Limited"}'

现在,当我搜索 "ABC International Pvt Ltd" 时,第一个文档的得分为 1.15,第二个文档的得分为 0.57。

有没有办法平等对待同义词?

使用以下设置创建索引:

curl -XPUT 'localhost:9200/test1?pretty' -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "index" : {
            "analysis":{
                "analyzer":{
                    "my_analyzer":{
                        "tokenizer":"standard",
                        "filter":["asciifolding", "standard", "lowercase", "my_metaphone", "synonym"]
                    }
                },
                "filter":{
                    "my_metaphone":{
                        "type":"phonetic",
                        "encoder":"metaphone",
                        "replace":false
                    },
                    "synonym" : {
                      "type" : "synonym", 
                      "synonyms_path" : "synonyms.txt",
                      "ignore_case" : "true"
                    }
                }
            }
        }
    }
}'

在创建索引时添加映射完成了这项工作。如果没有映射,同义词标记过滤器甚至不会被应用。下面是我用来创建索引的命令。

curl -XPUT 'localhost:9200/test1?pretty' -H 'Content-Type: application/json' -d' 
{
"settings" : {
  "analysis":{
    "filter":{
      "my_metaphone":{
        "type":"phonetic",
        "encoder":"metaphone",
        "replace":false
      },
      "synonym" : {
        "type" : "synonym", 
        "synonyms_path" : "synonym.txt",
        "ignore_case" : "true"
      }
    },
    "analyzer":{
      "my_analyzer":{
        "type":"custom",
        "tokenizer":"standard",
        "filter":["asciifolding", "standard", "lowercase", "my_metaphone", "synonym"]
      }
    }
  }
},
"mappings": {
  "test": {
    "properties": {
      "text": {
        "type": "text",
        "analyzer": "my_analyzer", 
        "search_analyzer": "my_analyzer" 
      }
    }
  }
}
}'