问题
I'm using elastic search to filter outfits:
def self.search(query)
__elasticsearch__.search(
{
query: {
function_score: {
query: {
multi_match: {
query: query,
fields: ['description^30','material^10']
},
},
field_value_factor: {
field: "purchased"
},
}
}
}
)
end
The problem is I can't seem to filter them by how many times they were purchased like this:
range: {
purchased: {
gte: 1000
}
}
Wherever I put this, it gives me the following error:
[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}
How do I write the range filter properly/put the code? Is there somewhere I can read more about this to understand how the hash should should be arranged?
回答1:
You can do it like this with a bool/filter
query:
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"
}
}
}
}
)
来源:https://stackoverflow.com/questions/46411276/elasticsearch-range-filter-with-multimatch