elasticsearch常用請求介面Rest API示例

是大尧啊發表於2024-03-09

建立shopping索引

PUT /shopping

檢視全部索引

GET /_cat/indices

檢視指定索引

GET /shopping

刪除指定索引

DELETE /shopping

索引的對映欄位屬性,是否關鍵字和加入索引

PUT /shopping/_mapping
{
  "properties": {
    "title": {
      "type": "text"
    },
    "category": {
      "type": "keyword"
    },
    "image":{
      "type": "keyword",
      "index": false
    },
    "price":{
      "type": "double"
    }
  }
}

新增文件

POST /shopping/_doc
{
  "title": "華為1手機",
  "category": "華為",
  "image": "https://baidu.com/123.jpg",
  "price": 2999.15
}

查詢指定id的文件

GET /shopping/_doc/d6B-I44BvNwAEbI4CH3-

修改指定id的文件

PUT /shopping/_doc/d6B-I44BvNwAEbI4CH3-
{
  "title": "華為2手機——修改"
}

刪除指定id的文件

DELETE /shopping/_doc/d6B-I44BvNwAEbI4CH3-

刪除所有匹配的文件

POST /shopping/_delete_by_query
{
  "query": {
    "match_all": {
      
    }
  }
}

查詢全部文件

GET /shopping/_search
{
  "query": {
    "match_all":{}
  }
}

查詢指定條件文件

GET /shopping/_search
{
  "query": {
    "match": {
      "category": "華為"
    }
  }
}

查詢指定條和定製結果件文件

GET /shopping/_search
{
  "query": {
    "match": {
      "category": "華為"
    }
   
  },
   "_source": ["title","price"]
}

相關文章