Elasticsearch 两种更新操作

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangqing84411433/article/details/86605773
 /**
     * 更新
     * @throws IOException
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @Test
    public void update1() throws IOException, ExecutionException, InterruptedException {
        UpdateRequest updateRequest = new UpdateRequest();
        updateRequest.index("twitter");
        updateRequest.type("tweet");
        updateRequest.id("AWQrxpiTF3aJ5qXnAM6l");
        updateRequest.doc(XContentFactory.jsonBuilder()
                .startObject()
                .field("age", 8)
                .endObject());
        client.update(updateRequest).get();
    }


    /**
     * 更新
     * @throws IOException
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @Test
    public void update2() throws IOException {
        client.prepareUpdate("twitter", "tweet", "AWQrxpiTF3aJ5qXnAM6l")
                .setDoc(XContentFactory.jsonBuilder()
                        .startObject()
                        .field("user", "male2")
                        .endObject())
                .get();
    }

猜你喜欢

转载自blog.csdn.net/wangqing84411433/article/details/86605773