1

我已经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”的查询,该查询位于同义词列表中。所以我希望包含单词Strawberryand的两个文档都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 知识的人都可以发现发生了什么?

4

0 回答 0