施比受有福

导航

elasticsearch增删查改

创建结构化索引

put http://127.0.0.1:9200/person
{
"settings" : { "number_of_shards": 3, "number_of_replicas": 0 }, "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" } } }, "woman": { } } }

删除索引

delete http://127.0.0.1:9200/person

 

插入(指定id)

put http://127.0.0.1:9200/person/man/1
{
    "name": "张三",
    "country": "China",
    "age": 30,
    "date": "2019-03-16"
}

插入(自动生成id)

post http://127.0.0.1:9200/person/man/
{
    "name": "李四",
    "country": "China",
    "age": 24,
    "date": "2019-03-15"
}

修改

post http://127.0.0.1:9200/person/man/1/_update
{
    "doc": {
        "name": "王五",
        "age": "25"
    }   
}

修改(使用脚本)

post http://127.0.0.1:9200/person/man/1/_update
//第一种方式

{
"script": { "lang": "painless", "inline": "ctx._source.age += 10" } }
//第二种方式
{
    "script": {
        "lang": "painless",
        "inline": "ctx._source.age = params.age",
        "params": {
            "age": 100
        }
    }   
}

删除

delete http://127.0.0.1:9200/person/man/1

查询

//查询单条记录
get http://127.0.0.1:9200/person/man/1

//查询所有数据
post http://127.0.0.1:9200/person/_search
{
    "query": {
        "match_all": {}
    }
}

//指定从第几条开始查,查询多少条数
post http://127.0.0.1:9200/person/_search
{
    "query": {
        "match_all": {}
    },
    "from":1,
    "size":1
}

//条件查询
post http://127.0.0.1:9200/person/_search
{
    "query": {
        "match": {
            "age": 24
        }
    }
}
//排序
post http://127.0.0.1:9200/person/_search
{
    "query": {
        "match": {
            "age": 24
        }
    },
    "sort": [
        {"age": {"order": "desc"}}
    ]
}

 

posted on 2019-03-16 10:45  施比受有福  阅读(122)  评论(0编辑  收藏  举报