美文网首页
ElasticSearch修改数据

ElasticSearch修改数据

作者: 思记享 | 来源:发表于2017-06-13 20:04 被阅读0次
    Paste_Image.png

    Elasticsearch provides data manipulation and search capabilities in near real time. By default, you can expect a one second delay (refresh interval) from the time you index/update/delete your data until the time that it appears in your search results. This is an important distinction from other platforms like SQL wherein data is immediately available after a transaction is completed.

    • ElasticSearch不像SQL类型数据库一样事物结束后即返回数据,而是有个刷新间隔

    Indexing/Replacing Documents

    PUT /customer/external/1?pretty
    {
    "name": "John Doe"
    }

    PUT /customer/external/1?pretty
    {
    "name": "Jane Doe"
    }

    执行上面的命令,第一条在新增一条记录,第二条因为id相应则会更新记录的name值

    Again, the above will index the specified document into the customer index, external type, with the ID of 1. If we then executed the above command again with a different (or same) document, Elasticsearch will replace (i.e. reindex) a new document on top of the existing one with the ID of 1:

    When indexing, the ID part is optional. If not specified, Elasticsearch will generate a random ID and then use it to index the document. The actual ID Elasticsearch generates (or whatever we specified explicitly in the previous examples) is returned as part of the index API call.

    This example shows how to index a document without an explicit ID:

    POST /customer/external?pretty
    {
    "name": "Jane Doe"
    }

    注意id是可选的,如果不指定id,则es会生成默认的

    Paste_Image.png

    Note that in the above case, we are using the POST verb instead of PUT since we didn’t specify an ID.

    注意上面使用了post而不是put方式,因为我们没有制定ID,这句话是什么意思呢,简单的理解可能不完全对,PUT是更新操作,POST是新增操作,对于post还是put方式可以参考下面的连接
    HTTP协议中PUT和POST使用区别

    Deleting Documents

    Deleting a document is fairly straightforward. This example shows how to delete our previous customer with the ID of 2:
    DELETE /customer/external/2?pretty

    上面是删除id=2的记录

    See the Delete By Query API to delete all documents matching a specific query. It is worth noting that it is much more efficient to delete a whole index instead of deleting all documents with the Delete By Query API.

    • 删除满足查询条件的记录请查看 Delete By Query API 文档

    Delete By Query API

    下面详细介绍,这部分在这里没有详细看,后续用到再看吧

    https://www.elastic.co/guide/en/elasticsearch/reference/5.3/docs-delete-by-query.html

    相关文章

      网友评论

          本文标题:ElasticSearch修改数据

          本文链接:https://www.haomeiwen.com/subject/cvdwxxtx.html