mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-23 05:15:04 +00:00
[DOCS] Low Level REST Client should emphasize ContentType (#22940)
This adds a callout to note that the Low Level REST Client example sets the `ContentType` explicitly and that users should do the same.
This commit is contained in:
parent
39e7c30912
commit
dabc51f988
@ -233,15 +233,19 @@ HttpEntity entity = new NStringEntity(
|
|||||||
" \"post_date\" : \"2009-11-15T14:12:12\",\n" +
|
" \"post_date\" : \"2009-11-15T14:12:12\",\n" +
|
||||||
" \"message\" : \"trying out Elasticsearch\"\n" +
|
" \"message\" : \"trying out Elasticsearch\"\n" +
|
||||||
"}", ContentType.APPLICATION_JSON);
|
"}", ContentType.APPLICATION_JSON);
|
||||||
|
|
||||||
Response indexResponse = restClient.performRequest(
|
Response indexResponse = restClient.performRequest(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/twitter/tweet/1",
|
"/twitter/tweet/1",
|
||||||
Collections.<String, String>emptyMap(),
|
Collections.<String, String>emptyMap(),
|
||||||
entity);
|
entity);
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
|
IMPORTANT: The `ContentType` that you specify for the `HttpEntity` is important
|
||||||
|
because it will be used to set the `Content-Type` header so that Elasticsearch
|
||||||
|
can properly parse the content. Future releases of Elasticsearch will require this
|
||||||
|
to be set properly.
|
||||||
|
|
||||||
Note that the low-level client doesn't expose any helper for json marshalling
|
Note that the low-level client doesn't expose any helper for json marshalling
|
||||||
and un-marshalling. Users are free to use the library that they prefer for that
|
and un-marshalling. Users are free to use the library that they prefer for that
|
||||||
purpose.
|
purpose.
|
||||||
@ -262,6 +266,7 @@ The following is a basic example of how async requests can be sent:
|
|||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
int numRequests = 10;
|
int numRequests = 10;
|
||||||
final CountDownLatch latch = new CountDownLatch(numRequests);
|
final CountDownLatch latch = new CountDownLatch(numRequests);
|
||||||
|
|
||||||
for (int i = 0; i < numRequests; i++) {
|
for (int i = 0; i < numRequests; i++) {
|
||||||
restClient.performRequestAsync(
|
restClient.performRequestAsync(
|
||||||
"PUT",
|
"PUT",
|
||||||
@ -283,6 +288,7 @@ for (int i = 0; i < numRequests; i++) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//wait for all requests to be completed
|
//wait for all requests to be completed
|
||||||
latch.await();
|
latch.await();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user