2017-10-17 142 views
1

我们可以在elasticsearch中平等地评分原始字符串和同义词吗?在Elasticsearch中同等评分同义词

例如,我创建了同义词文件为:

PVT,私人

有限公司,有限

我创建使用同义词象征过滤器的索引。然后我索引的两个文件:

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国际私人有限公司”,其总分第一文档为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" 
        } 
       } 
      } 
     } 
    } 
}' 
+1

你能说明如何定义索引的设置和映射吗? – Val

+0

有没有可能你有一个很少有文件的多分片索引?如果是这样,请尝试使用单个分片索引。评分发生在碎片级别,所以如果你没有很多文档,你会得到奇怪的结果。 – dshockley

回答

1

添加映射在创建索引做了工作。没有映射,同义词令牌过滤器甚至没有被应用。以下是我用来创建索引的命令。

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" 
     } 
    } 
    } 
} 
}'