我想为elasticsearch 1.7写这样的查询:
SELECT * FROM prods WHERE
id=1 AND
name='flower' AND
(count_usd=1 OR prise_usd=5) AND
(count_eur=1 OR prise_eur=5)
? 我已经了解了嵌套bool(https://www.elastic.co/guide/en/elasticsearch/guide/1.x/combining-filters.html),但无法将其应用于我的上下文: - (
答案 0 :(得分:0)
您可以在bool
查询中嵌套bool
查询以实现此类过滤:
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [{
"term": {"name":"flower"}
}],
"should": [{
"bool": {
"should": [{
"term": {
"count_usd": 1
}
}, {
"term": {
"prise_usd": 5
}
}]
}
}, {
"bool": {
"should": [{
"term": {
"count_eur": 1
}
}, {
"term": {
"prise_eur": 5
}
}]
}
}]
}
}
}
}
}
请注意,should
子句的作用类似于OR
:should
中至少有一个子句必须为true才能匹配。