我使用弹性搜索来过滤服装:
def self.search(query)
__elasticsearch__.search(
{
query: {
function_score: {
query: {
multi_match: {
query: query,
fields: ['description^30','material^10']
},
},
field_value_factor: {
field: "purchased"
},
}
}
}
)
端
问题是我似乎无法按照这样购买它们的次数来过滤它们:
range: {
purchased: {
gte: 1000
}
}
无论我把它放在哪里,都会给我以下错误:
[400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"[range] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":88}],"type":"parsing_exception","reason":"[range] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":88},"status":400}
如何正确编写范围过滤器/放置代码?有什么地方我可以阅读更多关于这个,以了解应该如何安排哈希?
答案 0 :(得分:0)
您可以使用bool/filter
查询执行此操作:
def self.search(query)
__elasticsearch__.search(
{
query: {
function_score: {
query: {
bool: {
filter: [
{
multi_match: {
query: query,
fields: ['description^30','material^10']
}
},
{
range: {
purchased: { gte: 1000}
}
}
]
}
},
field_value_factor: {
field: "purchased"
}
}
}
}
)