Elastic文档中有错误吗?
给定以下索引映射:
PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"usa,united states,u s a,united states of america"
]
}
},
"analyzer": {
"my_synonyms": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_synonym_filter"
]
}
}
}
}
}
鉴于此文件:
put /my_index/country/1
{
"title" : "The United States is wealthy"
}
在文档中指出:
这些词组不匹配:
美国很富有
美国富裕
美国很富有
但是,这些短语将:
美国富裕
美国富国
美国的富人
美国是美国
但是,似乎并非如此-应该匹配的短语根本不匹配!这是我正在运行的查询(根据documentation在查询时没有同义词扩展):
GET /my_index/country/_search
{
"query" : {
"match_phrase" : {
"title" : {
"query" : "United States is wealthy",
"analyzer": "standard"
}
}
}
}
我在这里想念什么?
最佳答案
文档中的示例对我有用。
您可能忘记了为映射中的title
字段设置分析器。
例:
1)创建索引
PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"usa,united states,u s a,united states of america"
]
}
},
"analyzer": {
"my_synonyms": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_synonym_filter"
]
}
}
}
}
}
2)添加映射
PUT my_index/country/_mapping
{
"properties" : {
"title" : {"type" : "string","analyzer" : "my_synonyms"}
}
}
3)索引文件
PUT /my_index/country/1
{
"title" : "The United States is wealthy"
}
4)查询
GET /my_index/country/_search
{
"query" : {
"match_phrase" : {
"title" : {
"query" : "United States is wealthy",
"analyzer": "standard"
}
}
}
}
5)回应:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.75942194,
"hits": [
{
"_index": "my_index",
"_type": "country",
"_id": "1",
"_score": 0.75942194,
"_source": {
"title": "The United States is wealthy"
}
}
]
}
}
关于elasticsearch - 多字同义词和短语查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32126226/