es java 更新操作

两种更新方式:

 /**
     * 更新
     * @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(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(jsonBuilder()
                        .startObject()
                        .field("user", "male2")
                        .endObject())
                .get();
    }

你可能感兴趣的:(ElasticSearch)