elasticsearch 文档操作

PUT方式创建文档

curl -H 'Content-Type:application/json' -XPUT http://118.195.173.53:9200/user/_doc/1 -d '{
 "id":1,
 "name":"huyongjian",
 "age":25
 }'
curl -H 'Content-Type: application/json' -XPUT 'http://118.195.173.53:9200/user/_create/3' -d '{
    "id":2,
     "name":"huyongjian2",
     "age":23
     }'

POST方式创建文档

curl -H 'Content-Type:application/json' -XPOST http://118.195.173.53:9200/user/_doc/1 -d '{
 "id":2,
 "name":"huyongjian2",
 "age":23
 }'

获取文档

CURL -XGET http://118.195.173.53:9200/user/_doc/1

返回结果

{
    "_index": "user",
    "_type": "_doc",
    "_id": "1",
    "_version": 3,
    "_seq_no": 7,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "id": 2,
        "name": "huyongjian2",
        "age": 23
    }
}
CURL -XGET http://118.195.173.53:9200/user/_search
{
    "took": 488,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 3,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [{
            "_index": "user",
            "_type": "_doc",
            "_id": "pP6SZHwBWXwnSqDxUPGj",
            "_score": 1.0,
            "_source": {
                "id": 1,
                "name": "huyongjian3",
                "age": 23
            }
        }, {
            "_index": "user",
            "_type": "_doc",
            "_id": "1",
            "_score": 1.0,
            "_source": {
                "id": 2,
                "name": "huyongjian2",
                "age": 23
            }
        }, {
            "_index": "user",
            "_type": "_doc",
            "_id": "3",
            "_score": 1.0,
            "_source": {
                "id": 2,
                "name": "huyongjian2",
                "age": 23
            }
        }]
    }
}

更新文档

curl -H 'Content-Type:application/json' -XPUT 'http://118.195.173.53:9200/user/_doc/3' -d '{
 "age": 50
 }'
curl -H 'Content-Type: application/json' -XPOST 'http://118.195.173.53:9200/user/_doc/1' -d '{
"age": 33
}'
curl -H 'Content-Type: application/json' -XPOST 'http://118.195.173.53:9200/user/_doc/1/_update' -d '{
"doc":{
"name":"huyongjian"
}
}'
posted @ 2021-10-10 00:20  胡勇健  阅读(64)  评论(0)    收藏  举报