1. 程式人生 > >elasticsearch增刪查改

elasticsearch增刪查改

pos settings 增刪查改 pda += 127.0.0.1 param from int

創建結構化索引

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"}}
]
}

elasticsearch增刪查改