六 ES增删改查操作

    xiaoxiao2025-07-29  15

    一 查询

    get /test_index/test_type/1

    {   "_index": "test_index",   "_type": "test_type",   "_id": "1",   "_version": 2,   "found": true,   "_source": {     "test_field1": "test field1",     "test_field2": "test field2",

         "test_field3": "test field3"   } }

    1. "_source": 在创建document的时候,使用的request body中的json串。默认情况下,在get的时候,会原封不动的给我们返回回来。

    2. 查询指定字段

    定制返回的结果,指定_source中,返回哪些field

    GET /test_index/test_type/1?_source=test_field1,test_field2

    {   "_index": "test_index",   "_type": "test_type",   "_id": "1",   "_version": 2,   "found": true,   "_source": {     "test_field1": "test field1",

        "test_field2": "test field2"   } }

    二 document的全量替换

    1. 语法与创建文档是一样的,如果document id不存在,那么就是创建;如果document id已经存在,那么就是全量替换操作,替换document的json串内容 2. document是不可变的,如果要修改document的内容,第一种方式就是全量替换,直接对document重新建立索引,替换里面所有的内容 3. es会将老的document标记为deleted,然后新增我们给定的一个document,当我们创建越来越多的document的时候,es会在适当的时机在后台自动删除标记为deleted的document

    三 document的强制创建

    1. 创建文档与全量替换的语法是一样的,有时我们只是想新建文档,不想替换文档,如果强制进行创建呢? 2. PUT /index/type/id?op_type=create,PUT /index/type/id/_create

    四 document的删除

    DELETE /index/type/id 不会进行物理删除,只会将其标记为deleted,当数据越来越多的时候,在后台自动删除

    最新回复(0)