[学习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"
        }
    }
}

删除操作

猜你喜欢

转载自blog.51cto.com/phpme/2344993