Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

According to the documentation getting-started-java adjustment Indexi… #740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

qq943260285
Copy link

…ngTest.java update doc

According to the documentation https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/getting-started-java.html,Update exception (Validation Failed: 1: script or doc is missing;)

@wordscode
Copy link

+1
@test
public void updateDoc() throws Exception {
//tag::single-doc-update
Product product = new Product("bk-1", "City bike", 666);

    esClient.update(u -> u
                    .index("products")
                    .id("bk-1")
                    .upsert(product),
            Product.class
    );
    //end::single-doc-update
}

报错:
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/update] failed: [action_request_validation_exception] Validation Failed: 1: script or doc is missing;

at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:338)
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:140)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2201)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2218)
at com.example.gp.EsTest.updateDoc(EsTest.java:93)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

我执行下列代码都是成功的:
@test
public void singleDocumentDSL() throws Exception {

    //tag::single-doc-dsl
    Product product = new Product("bk-1", "City bike", 123.0);

    IndexResponse response = esClient.index(i -> i
            .index("products")
            .id(product.getSku())
            .document(product)
    );

    log.info("Indexed with version " + response.version()); //每当对文档执行更新操作时,版本号会增加,以便跟踪文档的变化历史。
    //end::single-doc-dsl
}

 @Test
public void deleteDocument() throws Exception {
    esClient.delete(d -> d.index("products").id("bk-1"));
}  

@qq943260285
Copy link
Author

qq943260285 commented Mar 6, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants