栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

跨字段搜索,每个字段中有多个完整和不完整的短语

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

跨字段搜索,每个字段中有多个完整和不完整的短语

是的,我必须使用分析仪…

添加任何数据之前,在创建索引时将分析器应用于这些字段。添加数据后,我找不到更简单的方法来执行此操作。

我发现的解决方案是将所有短语分解成每个单独的前缀,因此

cross_fields
可以做到这一点。您可以在
edge-ngram

此处了解有关使用的更多信息。

因此,而不是

cross_field
只是搜索
cats
短语,它现在要搜索:
c
ca
cat
,和
cats
和每句话后......所以
text1
场将看起来像这样弹性:
cca cat cats m me meo meow

~~~

以下是使上述问题示例起作用的步骤:

首先,您创建并命名分析器。要了解多一点什么过滤器的值的含义,我建议你看看这个。

PUT /test{    "settings": {        "number_of_shards": 1,         "analysis": { "filter": {     "autocomplete_filter": {          "type":     "edge_ngram",         "min_gram": 1,         "max_gram": 20     } }, "analyzer": {     "autocomplete": {         "type":      "custom",         "tokenizer": "standard",         "filter": [  "lowercase",  "autocomplete_filter"          ]     } }        }    }}

然后,我将此分析仪附加到每个字段。我更改了,

text1
以匹配我将其应用到的字段。

PUT /test/_mapping/test{    "test": {        "properties": { "text1": {     "type":     "string",     "analyzer": "autocomplete" }        }    }}

我跑来

GET /test/_mapping
确保一切正常。

然后添加数据:

POST /test/test/_bulk{ "index": { "_id": 1 }}{ "text1": "cats meow", "text2": "12345", "text3": "toy" }{ "index": { "_id": 2 }}{ "text1": "dog bark", "text2": "98765", "text3": "toy" }

和搜索!

{    "size": 25,    "query": {        "multi_match" : { "fields" : [     "text1",      "text2",     "text3" ], "query" : "cat toy", "type" : "cross_fields"        }    }}

哪个返回:

{   "took": 3,   "timed_out": false,   "_shards": {      "total": 1,      "successful": 1,      "failed": 0   },   "hits": {      "total": 2,      "max_score": 0.70778143,      "hits": [         { "_index": "test", "_type": "test", "_id": "1", "_score": 0.70778143, "_source": {    "text1": "cats meow",    "text2": "12345",    "text3": "toy" }         },         { "_index": "test", "_type": "test", "_id": "2", "_score": 0.1278426, "_source": {    "text1": "dog bark",    "text2": "98765",    "text3": "toy" }         }      ]   }}

当您搜索时

cattoy
,这会在两者之间形成对比,而之前的分数是相同的。但是现在,这
cat
首热门歌曲的得分更高了。这是通过考虑每个词组的每个前缀(在这种情况下/短语中最多20个字符),然后查看数据与的相关性来实现的
cross_fields



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/409527.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号