Elastic Search 8.3 integration Issue with Rest High Client 7.17.6

Hi Team,

We are currently working on 6.3 Version of ES and 6.4v of RestHighLevelClient we are upgrading to ES 8.3v so the code written in earlier version of ES with RestHigh client we are facing challenges to upgrade.

Current ES 8.3 and RestHighClient 7.17.6 we are trying to createIndex with below snippet

private boolean createIndex() throws Exception {
CreateIndexRequest createIndexRequest = new CreateIndexRequest("giftcard_1");
createIndexRequest.settings(PARTIAL_MATCH_INDEX_SETTING, XContentType.JSON);
createIndexRequest.mapping(type, GIFT_CARD_MAPPING, XContentType.JSON);
CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
return createIndexResponse.isAcknowledged();

Where the Constants used in Code are
static final String PARTIAL_MATCH_INDEX_SETTING = "{\r\n" +
" "analysis": {\r\n" +
" "analyzer": {\r\n" +
" "partial_search_analyzer": {\r\n" +
" "tokenizer": "partial_tokenizer",\r\n" +
" "filter": [\r\n" +
" "lowercase"\r\n" +
" ]\r\n" +
" }\r\n" +
" },\r\n" +
" "tokenizer": {\r\n" +
" "partial_tokenizer": {\r\n" +
" "type": "edge_ngram",\r\n" +
" "min_gram": 3,\r\n" +
" "max_gram": 3,\r\n" +
" "token_chars": [\r\n" +
" "letter",\r\n" +
" "digit",\r\n" +
" "symbol",\r\n" +
" "punctuation",\r\n" +
" "whitespace"\r\n" +
" ]\n" +
" }\n" +
" }\n" +
" }\n" +
"}";

static final String GIFT_CARD_MAPPING = "{\r\n" +
" "properties": {\r\n" +
" "bhn": {\r\n" +
" "properties": {\r\n" +
" "brandDescription": {\r\n" +
" "properties": {\r\n" +
" "eng": {\r\n" +
" "type": "text",\r\n" +
" "fields": {\r\n" +
" "keyword": {\r\n" +
" "type": "keyword",\r\n" +
" "ignore_above": 256\r\n" +
" }\r\n" +
" },\r\n" +
" "analyzer": "partial_search_analyzer"\r\n" +
" },\r\n" +
" "spa": {\r\n" +
" "type": "text",\r\n" +
" "fields": {\r\n" +
" "keyword": {\r\n" +
" "type": "keyword",\r\n" +
" "ignore_above": 256\r\n" +
" }\r\n" +
" },\r\n" +
" "analyzer": "partial_search_analyzer"\r\n" +
" }\r\n" +
" }\r\n" +
" },\r\n" +
" "brandName": {\r\n" +
" "properties": {\r\n" +
" "eng": {\r\n" +
" "type": "text",\r\n" +
" "fields": {\r\n" +
" "keyword": {\r\n" +
" "type": "keyword",\r\n" +
" "ignore_above": 256\r\n" +
" }\r\n" +
" },\r\n" +
" "analyzer": "partial_search_analyzer"\r\n" +
" },\r\n" +
" "spa": {\r\n" +
" "type": "text",\r\n" +
" "fields": {\r\n" +
" "keyword": {\r\n" +
" "type": "keyword",\r\n" +
" "ignore_above": 256\r\n" +
" }\r\n" +
" },\r\n" +
" "analyzer": "partial_search_analyzer"\r\n" +
" }\r\n" +
" }\r\n" +
" }\r\n" +
" }\r\n" +
" }\r\n" +
" }\r\n" +
"}";

But when we are trying to execute this piece of code snipped we get the below Exception

[________,[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)']:E: 12 08:42:34.032: GCCatalogSchedulerJob.performScheduledJob: Fatal Exception occurred in GCCatalog Scheduler Job : java.lang.Exception: ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, reason=request [/giftcards_1] contains unrecognized parameter: [include_type_name]]]
[________,[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)']:I: 12 08:42:34.033: GCCatalogSchedulerJob.performScheduledJob: GiftCard get Catalog : Total Time taken to update catalog: 4280
[________,[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)']:I: 12 08:42:34.033: GCCatalogSchedulerJob.performScheduledJob: Giftcard Catalog Scheduler End Date & Time : 01/12/2023 08:42:34

Note the code fails when working with ES 8.3 with RestHighClient 7.17.6 intergration, when i run the above Mappings & Setting defined in constants directly on ES devtools they work FINE(with No ERROR)

Please Assist any help would be Appreciated!!!

Have you enabled compatibility mode in your Rest High Level Client? This allows Elasticsearch 8 to know that it's called by a client for version 7.x and use a compatible API.

Thanks Sylvain Sir,

Here is our code for connecting, can you suggest where we can integrate the set compatibility part??

Code Snippet
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(propertyConfig.getUserName(), propertyConfig.getPassword()));
RestClientBuilder builder = RestClient.builder(new HttpHost(propertyConfig.getEsHost(),
Integer.parseInt(propertyConfig.getEsPort()), propertyConfig.getEsSchema())).setHttpClientConfigCallback(httpClientBuilder ->
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
RestHighLevelClient client = new RestHighLevelClient(builder);

        return client; 

Thanks
Siddharth

Please see the example in the documentation, it's pretty straightforward.

Also, it would be nice if you could format the code snippets correctly in your posts. As it is, they are quite hard to read. Thanks!

Thanks Sylvain , we tried but faced issue

I am resending the code

Code Snippet


final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(propertyConfig.getUserName(), propertyConfig.getPassword()));

RestClientBuilder builder = RestClient.builder(new HttpHost(propertyConfig.getEsHost(),
Integer.parseInt(propertyConfig.getEsPort()), propertyConfig.getEsSchema())).setHttpClientConfigCallback(httpClientBuilder ->
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));

RestHighLevelClient client = new RestHighLevelClient(builder);

return client;

Thanks
Siddharth

Hi Sylvain

What object is restClient in the below code

RestHighLevelClient esClient = new RestHighLevelClientBuilder(restClient)
    .setApiCompatibilityMode(true)
    .build()

Thanks
Siddharth

Thanks Sylvain , for you assistance we figured out and fixed the issue