弹性搜索复杂方案 [英] Elastic Search Complex Scenario
问题描述
我是Elastic Search的新手.我的场景很复杂,无法为此找到正确的解决方案(弹性查询/参数).任何帮助将不胜感激.
I am quite new to Elastic Search. I have a complex scenario and I am unable to get the right solution(Elastic Queries/params) for this. Any Help would be highly appreciate.
我的田地
- 产品名称(字符串)
- 最低价格
- 最高价格
- 可用性状态(可用/不可用)
除此之外,搜索始终会针对唯一用户进行过滤.所以Mysql查询看起来像:
Beside of these a search will always be filter on unique user. So Mysql query looks like :
Select * from product where product_name like %xxx% AND price >= price_min AND price <= price_max AND availability = availability_ status AND user = 1;
我喜欢精确的弹性搜索参数来解决这种情况,否则也将了解解决方案.
I like the exact elastic search params to solve this scenario Or near about solution will also be appreciated.
推荐答案
您将需要在此处使用过滤器,因为您需要完全匹配而不是全文匹配.而且这种方式甚至更快.
You will need to use a filter here since you need an exact match and not a full-text match. And this way its even faster.
{
"query": {
"filtered": {
"query": {
"match": { "name": "YourName" }
},
"filter": {
"bool": {
"must": [
{ "range": { "price_min": { "gte": 20 }}},
{ "range": { "price_max": { "lte": 170 }}},
{ "term" : { "availability" : "false" }} ]
}
}
}
}
}
您在您的姓名"中提供的是全文匹配项(如果对名称字段进行了分析,则将检索相似的名称).我假设您保持不变,因此默认情况下会分析该字段(删除词干+停用词). 由于您需要结果来匹配所有条件,因此必须将其AND组合在一起.因此使用
What you provide in "yourName" is a full text match (Similar names will be retrieved if the name field is analyzed). Im assuming that you have left it unchanged so the field is analyzed(Stemmed + stop words removal) by default. Since you need the result to match all the criteria its an AND combination. Hence use
对所有条款进行布尔过滤.
bool filter to AND all the terms.
这篇关于弹性搜索复杂方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!