Elasticsearch的或且非及其组合

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}}
                                             ]
                                    }
                         }
                      ]
                    }
                 }
              ]
      }
   }
}
发布了41 篇原创文章 · 获赞 23 · 访问量 14万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览