在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" } } }更多推荐
发布评论