[學習ES系列]-3.ElasticSearch基礎交互

RESTful API with JSON over HTTP

創建索引

PUT http://127.0.0.1:9200/people

{
    "setting":{
        "number_of_shards":5,
        "number_of_replicas":1
    },
    "mappings":{
        "man":{
            "properties":{
                "name":{
                    "type":"text"
                },
                "country":{
                    "type":"keyword"
                },
                "age":{
                    "type":"integer"
                },
                "date":{
                    "type":"date",
                    "format":"yyyy-MM-dd HH:mm::ss||yyyy-MM-dd||epoch_millis"
                }
            }
        }
    }
}

創建結構

結構化創建 需要利用mappings 結構化關鍵詞。

POST http://127.0.0.1:9200/book/cs/_mappings

{
  "cs": {
    "properties": {
      "title": {
        "type": "text"
      }
    }
  }
}

插入數據

{
    "name":"張仁杰",
    "country":"China",
    "age":30,
    "date":"1987-06-01"
}
{
    "name":"張惠",
    "country":"China",
    "age":28,
    "date":"1990-11-01"
}

修改數據

{
    "doc":{
        "name":"Jack",
        "age":31
    }
}
  • 2.通過腳本方式修改
    painless內置的腳本語言
    ctx._source.age+=10
    ctx上下文
    source當前文檔

POST http://127.0.0.1:9200/people/man/1/_update

{
    "script":{
        "lang":"painless",
        "inline":"ctx._source.age-=10"
    }
}
{
    "script":{
        "lang":"painless",
        "inline":"ctx._source.age=params.age",
        "params":{
            "age":"100"
        }
    }
}

刪除操作

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章