ElasticSearch客戶端簡單操作例項

zhaozhangxiao發表於2021-09-08

參考部落格地址:
juejin.cn/post/6939421220437753870

# 檢測連結是否正常
GET /_cluster/health

# 查詢所有索引
GET /_cat/indices?v

# 查詢某個索引下所有資料
GET /kibana_sample_data_ecommerce/_search

# 1.單個條件模糊查詢
POST /kibana_sample_data_ecommerce/_search
{
  "query": {
    "match": {
      "products.product_id": "6283"
    }
  }
}

# 2.多個條件模糊查詢
POST /kibana_sample_data_ecommerce/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "sku": "ZO0549605496"
          }
        },
        {
          "match": {
            "products.product_id": 6283
          }
        }
      ]
    }
  }
}

# 3.多個條件IN精確查詢

POST /kibana_sample_data_ecommerce/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "order_id": [584021,584058]
          }
        }
      ]
    }
  }
}

# 4.查詢範圍range用法
POST /kibana_sample_data_ecommerce/_search
{
  "query": {
    "range": {
      "order_date": {
        "gte": "2020-09-19T21:59:02+00:00",
        "lte": "2021-09-19T21:59:02+00:00"
      }
    }
  }
}

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章