Reputation: 7566
Elastic are updating their docs to use the RestHighLevelClient with Java now. It also has a mapping API:
Now how do you make a request like this with that API?
PUT /test
{
"settings": {
"analysis": {
"filter": {
"email": {
"type": "pattern_capture",
"preserve_original": 1,
"patterns": [
"([^@]+)",
"(\\p{L}+)",
"(\\d+)",
"@(.+)",
"([^-@]+)"
]
}
},
"analyzer": {
"email": {
"tokenizer": "uax_url_email",
"filter": [
"email",
"lowercase",
"unique"
]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "string",
"analyzer": "email"
}
}
}
}
}
Are you supposed to split it in two requests and use this API for the second request? https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-indices-put-settings.html
Or is the RestHighLevelClient intended for high performance operations, but for initial configuration you are free to use RestTemplate (Spring) or any other normal Java Rest Client?
Upvotes: 3
Views: 1768
Reputation: 1566
As you can see in the docs:
PutMappingRequest request = new PutMappingRequest("twitter");
request.type("tweet");
You can set the payload of this request using your definition as String
request.source(
"{\n" +
" \"properties\": {\n" +
" \"message\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
"}",
XContentType.JSON);
or a Map with your properties or even the XContentBuilder
.
With the low-level client you execute any kind of requests, including the one your are looking for.
As regards the name, I think that HighLevel refers to the fact that methods are provided (aka re-usability, convenience) to create the requests and one is not forced to implement the rest requests themselves. You can always use the RestTemplate. Note the HighLevelRestClient uses the apache HttpClient internally.
But for the code maintainability, I would choose one way to go. (Low-High level or any http-client).
from docs (Note the RestHighLevelClient is built upon the low level one.)
The low-level Java REST client internally uses the Apache Http Async Client to send http requests. It depends on the following artifacts, namely the async http client and its own transitive dependencies:
- org.apache.httpcomponents:httpasyncclient
- org.apache.httpcomponents:httpcore-nio
- org.apache.httpcomponents:httpclient
- org.apache.httpcomponents:httpcore
- commons-codec:commons-codec
- commons-logging:commons-logging
Upvotes: 4