如何在Elasticsearch中查找与我的搜索字段相关的相关记录(How to find the related record that is related to my search field

编程入门 行业动态 更新时间:2024-10-28 04:23:36
如何在Elasticsearch中查找与我的搜索字段相关的相关记录(How to find the related record that is related to my search field in Elasticsearch)

在Elasticsearch中,我想找到与我的搜索字段相关的相关记录,例如与stackoverflow相关的问题建议。这意味着,匹配彼此接近的搜索结果。

例如,我从以下数据中搜索“Men's Shoe”

“男士鞋” “女孩的鞋子” “男士鞋黑色” “女鞋” “女鞋粉红色” “女鞋红色” “男孩的鞋子” “男士鞋灰色” “男士鞋白色” “男士鞋绿色” “男士鞋”

那我怎么能用搜索项目“Men's Shoe”获得更多相关元组? 我怎样才能获得与同义词相关的数据,即。 男士鞋类。

散装Inser在Kibana

POST /atomap/product/_bulk {"index":{"_id":"1"}} {"name": "Girl's Shoe"} {"index":{"_id":"2"}} {"name": "Men's Shoe"} {"index":{"_id":"3"}} {"name": "Women's Shoe"} {"index":{"_id":"4"}} {"name": "Women's Shoe pink color"} {"index":{"_id":"5"}} {"name": "Women's Shoe red color"} {"index":{"_id":"6"}} {"name": "Boy's Shoe"} {"index":{"_id":"7"}} {"name": "Men's Shoe red color"} {"index":{"_id":"8"}} {"name": "Men's Shoe white color"} {"index":{"_id":"9"}} {"name": "Men's Shoe green color"} {"index":{"_id":"10"}} {"name": "Men's Shoe gray color"} {"index":{"_id":"11"}} {"name": "Men's footwear"}

我试过more like this查询:

GET /atomap/product/_search { "query": { "more_like_this": { "like": "Men's shoe", "min_term_freq": 1, "min_doc_freq": 1 } } }

我的问题是如何搜索相关单词? 当我搜索“Men's Shoe”时, 更多像这个查询找不到“男士鞋”。

In Elasticsearch I want to find the related record that is relevant to my search field like stackoverflow related question suggestion.That means, Matches search result which are near one another.

For example I search "Men's Shoe" from the following data

"Men's Shoe" "Girl's Shoe" "Men's Shoe black color" "Women's Shoe" "Women's Shoe pink color" "Women's Shoe red color" "Boy's Shoe" "Men's Shoe gray color" "Men's Shoe white color" "Men's Shoe green color" "Men's footwear"

Then how I can get more related tuple with search item "Men's Shoe" ? And how can I get data related to synonym also ie. Men's footware.

Bulk Insert in Kibana

POST /atomap/product/_bulk {"index":{"_id":"1"}} {"name": "Girl's Shoe"} {"index":{"_id":"2"}} {"name": "Men's Shoe"} {"index":{"_id":"3"}} {"name": "Women's Shoe"} {"index":{"_id":"4"}} {"name": "Women's Shoe pink color"} {"index":{"_id":"5"}} {"name": "Women's Shoe red color"} {"index":{"_id":"6"}} {"name": "Boy's Shoe"} {"index":{"_id":"7"}} {"name": "Men's Shoe red color"} {"index":{"_id":"8"}} {"name": "Men's Shoe white color"} {"index":{"_id":"9"}} {"name": "Men's Shoe green color"} {"index":{"_id":"10"}} {"name": "Men's Shoe gray color"} {"index":{"_id":"11"}} {"name": "Men's footwear"}

I have tried with more like this query:

GET /atomap/product/_search { "query": { "more_like_this": { "like": "Men's shoe", "min_term_freq": 1, "min_doc_freq": 1 } } }

My question is How can I search for related words? As More Like This Query can not find "Men's Footwear" in top when I search "Men's Shoe".

最满意答案

创建同义词和字段映射:

PUT /atomap { "settings": { "analysis": { "filter": { "my_synonym_filter": { "type": "synonym", "synonyms": [ "shoe,footwear", "color,colour" ] } }, "analyzer": { "my_synonyms": { "tokenizer": "standard", "filter": [ "lowercase", "my_synonym_filter" ] } } } }, "mappings":{ "product" : { "properties" : { "name" : { "type" : "string", "analyzer" : "my_synonyms" } } } } }

然后插入所有数据,之后运行以下查询:

POST /myshop/_search { "query": { "query_string": { "default_field": "name", "query": "Men's shoe", "analyzer": "my_synonyms" } } }

Create synonyms and field mapping:

PUT /atomap { "settings": { "analysis": { "filter": { "my_synonym_filter": { "type": "synonym", "synonyms": [ "shoe,footwear", "color,colour" ] } }, "analyzer": { "my_synonyms": { "tokenizer": "standard", "filter": [ "lowercase", "my_synonym_filter" ] } } } }, "mappings":{ "product" : { "properties" : { "name" : { "type" : "string", "analyzer" : "my_synonyms" } } } } }

Then insert all data, after that run the following query:

POST /myshop/_search { "query": { "query_string": { "default_field": "name", "query": "Men's shoe", "analyzer": "my_synonyms" } } }

更多推荐

本文发布于:2023-08-05 03:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   如何在   Elasticsearch   find   field

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!