我创建了两个索引时尚和手机与字段“名称”。如何在弹性搜索中匹配不匹配的单词,如“iphone手机”中的文档如“iphone”
client.indices.create(index='fashion',body={"mappings": {"doc": {"properties": {"name": {"type": "string"} } } } })
client.indices.create(index='mobiles',body={"mappings": {"doc": {"properties": {"name": {"type": "string"} } } } })
对于时尚,下面的文件被添加。
client.index(index='mobiles',doc_type='blog',body={"query":{ "name": "i shirts" }})
client.index(index='mobiles',doc_type='blog',body={"query":{ "name": "i celekon" }})
client.index(index='mobiles',doc_type='blog',body={"query":{ "name": "satsung" }})
对于手机:
client.index(index='mobiles',doc_type='blog',body={"query":{ "name": "apple iphone 6s" }})
client.index(index='mobiles',doc_type='blog',body={"query":{ "name": "samsung galaxy s2" }})
client.index(index='mobiles',doc_type='blog',body={"query":{ "name": "apple iphone 5s" }})
当我用匹配查询搜索术语像
search="i phone"
test=client.search(index='mobiles,fashion',doc_type='blog',size=10,body={"query": {"bool" : {"should" : [{"match": {"name": {"query":search,"slop": 10,"max_expansions": 2 }}},{"match_phrase_prefix": {"name": {"query":search,"slop": 10,"max_expansions": 2}}},{"match": {"name": {"query":search, "fuzziness":1}}}]}}})
我得到以下顺序结果..
我的衬衫,我celekon,苹果iphone 6s,苹果iphone 5s
我该如何跟踪结果?
苹果iPhone 6S,苹果iPhone 5S,....
如何 “亚马逊”, “flipkart” 实现这些类型的搜索?
注意:我用elasticsearch-py api来进行搜索。
如果“iphone”较低情况下,我们会怎么做呢@Evaldas Buinauskas – Println
你以后这个权利适用'lowercase'令牌过滤器,那么iPhone iphone iphone和我的手机应该被视为相同的关键字。 –