弹性搜索:部分搜索无法正常工作

部分搜索不适用于多个字段。


数据:-“ Sales inquiries generated”。


{

    "query_string": {

        "fields": ["name", "title", "description", "subject"],

        "query": search_data+"*"

    }

}

  • 案例 1:当我将搜索数据作为“inquiri”传递时它工作正常,但是当我将搜索数据作为“inquirie”传递时它不起作用。

  • 案例 2:当我将搜索数据作为“销售”传递时,它工作正常,但是当我将搜索数据作为“销售”传递时,它不起作用。

  • 案例 3:当我将搜索数据作为“generat”传递时,它工作正常,但是当我将搜索数据作为“generate”传递时,它不起作用。

我这样定义我的领域。

text_analyzer = analyzer("text_analyzer", tokenizer="standard", filter=["lowercase", "stop", "snowball"])



name = Text(analyzer=text_analyzer, fields={"raw": Keyword()})

title = Text(analyzer=text_analyzer, fields={"raw": Keyword()})

subject = Text(analyzer=text_analyzer, fields={"raw": Keyword()})

我的代码有什么问题?任何帮助将非常感激!提前致谢。


富国沪深
浏览 73回答 1
1回答

慕少森

这是由于使用了snowball词干的令牌过滤器而发生的,请参阅官方雪球文档以获取更多信息。我使用您的设置创建了相同的分析器,以查看为您的文本生成的标记,因为当索引标记与搜索词标记匹配时,搜索就会发生。ES 提供了很好的 REST api,你可以很容易地重现这个问题:使用您的设置创建索引{&nbsp; &nbsp; "settings": {&nbsp; &nbsp; &nbsp; &nbsp; "analysis": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "analyzer": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "my_analyzer": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "tokenizer": "standard",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "filter": [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lowercase",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "snowball",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "stop"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; },&nbsp; &nbsp; "mappings": {&nbsp; &nbsp; &nbsp; &nbsp; "properties": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "name": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "type": "text",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "analyzer": "my_analyzer"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}创建索引后,您可以使用分析 API查看为您的文本生成的标记。POST http://{{hostname}}:{{port}}/{{index-name}}/_analyze{&nbsp; "analyzer": "my_analyzer",&nbsp; "text": "Sales inquiries generated"}{&nbsp; &nbsp; "tokens": [&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "token": "sale",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "start_offset": 0,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end_offset": 5,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "type": "<ALPHANUM>",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "position": 0&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "token": "inquiri",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "start_offset": 6,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end_offset": 15,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "type": "<ALPHANUM>",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "position": 1&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "token": "generat",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "start_offset": 16,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end_offset": 25,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "type": "<ALPHANUM>",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "position": 2&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ]}您可以看到所有与您的搜索查询匹配的标记都是相同的,因此您将获得其他搜索词的结果,这意味着在查询而不是原始查询时,您使用的是文本字段的关键字部分
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python