我有一个产品索引,我想找到满足条件的所有产品,例如:
10)或(type = "apple"价格>8)) and on_sale=True.
怎么样(style = "orange"or type = "apple") and (price <= 25 or on_sale=True) .
您需要将bool子句与"must"one_answers";should"。在下面查找第一个语句
所需的查询GET _search
{
"query": {
"bool": {
"must": [
{
"term": {
"on_sale": {
"value": "True"
}
}
},
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"type": {
"value": "orange"
}
}
},
{
"range": {
"price": {
"gte": 10
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"type": {
"value": "apple"
}
}
},
{
"range": {
"price": {
"gte": 8
}
}
}
]
}
}
]
}
}
]
}
}
}
这只是关于包装"必须";或";Should"条款按要求相互转换。你需要一点练习才能弄清楚怎么把它们锁起来。但实际上,任何组合都可以使用这种语法进行查询。
第二个查询:
{
"query": {
"bool": {
"must": [
{
"terms": {
"type": [
"ornage",
"apple"
]
}
},
{
"bool": {
"should": [
{
"term": {
"on_sale": {
"value": "True"
}
}
},
{
"range": {
"price": {
"gte": 10
}
}
}
]
}
}
]
}
}
}
当你需要"one_answers"当你需要"必须"或"必须"时,使用"必须"。使用"SHOULD".
HTH .