ES常用操作

插入一条数据

PUT /pos_bill/_doc/001?routing=abc

{

    "billDate" : "20230715",

    "billSerialNumber" : "0001",

    "billType" : "601",

    "source":"2",  

    "createTime" : "20230715143000"

}

其中pos_bill为表名,001为id,routing根据表的mapping,mapping中有routing则添加,没有则不添加

查询一条数据

GET /pos_bill/_search

{

   "query": {

      "bool": {

         "must": [

            {

               "term": {

                  "shopId": {

                     "value": "1FD902S84"

                  }

               }

            }

         ]

      }

   }

}

删除一条数据

POST gag_daily_bill_info/_delete_by_query

{

  "query": {

    "term": {

      "_id": "77FCA5C399FA9E74F048AD8A131D8BE5"

    }

  }

}

修改一条数据

 post /merchant_datasource_daily_data/_update/0001?routing=1FGIGMH01QLK

 {

  "doc":{

          "isELeMeChannel" : "1",

          "isMeiTuanAuth" : "1",

          "isMeiTuanChannel" : "1",

          "iso2oAuth" : "1",

          "iso2oChannel" : "1"

  }

}

取某个字段的和

GET /benchmark_merchant_daily_data/_search

{

    "size": 0,

   "aggs": {

    "totalAmount": {

       "sum": {

          "field": "receivableAmount"

          }

        },

         "数量": {

       "sum": {

          "field": "collectSalesTotal"

          }

        }

       },           

   "query": {

      "bool": {

         "must": [

            {

               "term": {

                  "shopEntityId": {

                     "value": "1FGIHNM3QRP"

                  }

               }

            }

         ]

      }

   }

}

其中 "size": 0,为表中展示几条原有数据;aggs下面的俩sum为两个字段各自的和

只展示某些字段

{

   "size": 1000,
    "_source" : {
           "includes" : [ "_id","benchNetAmount",problemLocatingStatus"],
           "excludes" : [ ]
  },

   "query": {

      "bool": {

         "must": [            

            {

               "term": {

                  "shopId": {

                     "value": "S244"

                  }

               }

            }         

         ]

      }

   }

}

其中_source下的includes为展示的字段,excludes为不展示的字段

分组查询

GET /ads_sale_manage_shop_info_f/_search

{

    "query": {

      "bool": {

         "must": [

            {

               "term": {

                  "country": {

                     "value": "000001"

                  }

               }          

         ]

      }

      },   

"aggs": {

      "group1": {

         "terms": {

             "size": 10,

            "field": "cont_no"

         }     

      }

   }

}

查询某个时间段内的数据

GET /bill_transaction_detail_prod/_search

{

     "query": {

      "bool": {

         "must": [

                               {

               "range": {

                  "saleDate": {

                     "from": "2023-06-19",

                     "to": "2023-06-25"

                  }

               }

            }            

         ]         

      }

   }    

}

查询时,某个字段为数组中的一个

GET /gag_business_circles_pay_info/_search

{

   "query": {

      "bool": {

         "must": [

            {

               "term": {

                  "shopEntityId": {

                     "value": "1FGIHNM3QRPBTT725C889LSKTH001574"

                  }

               }

            },

             {

               "terms": {

                  "type": ["1","2"]              

               }

            }

         ]

      }

   }

}

查询不匹配

GET /shop_entity_sale_static/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "term": {
            "shopEntityId": "S00017244"
          }
        }
      ]

    }
  }
}


查询字段缺失

GET /my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {"missing": {"field": "age"}}
      ],
      "must_not": [
        {
          "term": {
            "shopEntityId": "S00017244"
          }
        }
      ]
    }
  }
}

查询某个字段存在

GET /my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {"exists": {"field": "title"}}
      ],
      "must_not": [
        {
          "term": {
            "title": "good"
          }
        }
      ]
    }
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值