我在本地电脑上设置了ES
并安装了Chrome Sense
。我现在正试图让同义词在multi_match
查询中工作,但只是没有随处可见。这是我的Sense查询,您尝试复制我正在看到的内容......
使用一些简单的同义词和基本词干等创建测试索引
POST /test
{
"settings" : {
"analysis" : {
"filter" : {
"synonym_expand" : {
"type" : "synonym",
"expand" : 1,
"synonyms" : [
"strawberry, apple, banana, grape, fruit",
"queen, king, monarch"
]
},
"english_stemmer" : {
"type" : "stemmer",
"language" : "english"
}
},
"analyzer" : {
"lens-english" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : [
"lowercase",
"stop",
"english_stemmer",
"synonym_expand"
]
}
}
}
},
"mappings" : {
"video" : {
"properties" : {
"Description" : {
"type" : "string",
"index_analyzer" : "lens-english",
"search_analyzer": "lens-english"
},
"Title" : {
"type" : "string",
"index_analyzer" : "lens-english",
"search_analyzer": "lens-english"
}
}
}
}
}
然后将2个文档发布到
POST /test/test
{
"Title" : "The diet plan",
"Description" : "Eat a lot of bananas and custard"
}
POST /test/test
{
"Title" : "The Queens visit",
"Description" : "this is the day that elizebeth when ape at her subjects for having a strawberry fight"
}
现在测试同义词是否已展开
GET /test/_settings
我发现他们确实这样做了。
如果我们现在通过分析器传递测试短语,我们会看到所有术语都被提取出来,因此应该被编入索引。
POST /test/_analyze?analyzer=lens-english
{Monarch fruit.}
到目前为止他们做的很棒!
现在我在这里搜索包含'fruit'的查询,它位于同义词列表中。所以我希望包含单词Strawberry
和banana
的两个文档都匹配,对吧?
GET /test/test/_search
{
"query": {
"multi_match": {
"query": "fruit",
"fuzziness":"AUTO",
"fields": [
"Title",
"Description"
]
}
},
"highlight": {
"fields": {
"Title":{},
"Description":{}
}
}
}
和......没什么,没有命中!
我甚至尝试更改映射部分,以便在搜索时使用标准分析器,如下所示
"mappings" : {
"video" : {
"properties" : {
"Description" : {
"type" : "string",
"index_analyzer" : "lens-english",
"search_analyzer": "standard"
},
"Title" : {
"type" : "string",
"index_analyzer" : "lens-english",
"search_analyzer": "standard"
}
}
}
}
但没有,纳达!
在这里有Elasticsearch知识的人可以发现正在发生的事情吗?