Elasticsearch的或且非及其组合
- 或
GET /my_store/products/_search
{
"query" :
{
"bool" :
{
"should" :
[
{ "term" : {"price" : 20}},
{ "term" : {"productID" : "XHDK-A-1293-#fJ3"}}
]
}
}
}
2 且
GET /my_store/products/_search
{
"query" :
{
"bool" :
{
"must" :
[
{ "term" : {"price" : 20}},
{ "term" : {"productID" : "XHDK-A-1293-#fJ3"}}
]
}
}
}
3 非
GET /my_store/products/_search
{
"query" :
{
"bool" :
{
"must_not" : {"term" : {"price" : 30} }
}
}
}
4 实现类似:
select * from products where (price = 20 or productID = '11111') and price != 30
GET /my_store/products/_search
{
"query" :
{
"bool" :
{
"should" :
[
{ "term" : {"price" : 20}},
{ "term" : {"productID" : "XHDK-A-1293-#fJ3"}}
],
"must_not" : {"term" : {"price" : 30} }
}
}
}
实现类似:
select * from products where productID = '11111' or (productID = '22222' and price = 30)
GET /my_store/products/_search
{
"query" :
{
"bool" :
{
"should" :
[
{ "term" : {"productID" : "XHDK-A-1293-#fJ3"}},
{ "bool" :
{
"must" :
[
{ "term" : {"productID" : "JODL-X-1937-#pV7"}},
{ "term" : {"price" : 30}}
]
}
}
]
}
}
}
实现类似:
select * from products where categaryID = '0301' and (productID = '11111' or (productID = '22222' and price = 30))
GET /my_store/products/_search
{
"query" :
{
"bool" :
{
"must" :
[
{ "term" : {"categaryID " : "0301"}},
{ "bool" :
{
"should" :
[
{ "term" : {"productID" : "11111"}},
{"bool" : {
"must" : [
{"term" : {"productID " : "22222"}},
{"term" : {"price" : 30}}
]
}
}
]
}
}
]
}
}
}