0

I am trying to create elasticsearch index using Java API , if we see below index mappings filed is coming as empty .

# curl -XGET localhost:9200/initest2
{"initest2":{"aliases":{},**"mappings":{}**,"settings":{"index":{"keyspace":"keyspace_test","number_of_shards":"5","provided_name":"initest2","max_result_window":"10000000","creation_date":"1671025346350","analysis":{"normalizer":{"testnormalizer":{"filter":["asciifolding"],"type":"custom","char_filter":[]}}},"number_of_replicas":"0","uuid":"BK9oTTKETZeWqiuR_tGd8w","version":{"created":"6080499"}}}}}

JAVA code :

String indexQuery = "";
        StringBuilder indexString = new StringBuilder("");
        String test = "{\"settings\": {\"max_result_window\":10000000,\"keyspace\":\""+keyspaceName+'\u0022' +",\"analysis\": "
                + "{\"normalizer\":{\"testnormalizer\": {\"type\": \"custom\",\"char_filter\": [],\"filter\": [\"asciifolding\"]}}}},"
                + "\"mappings\":{\""+tableName+"\":{\"discover\" : \".*\",\"properties\":{";
        indexString.append(test);

        for (String i : indexColumns)
        {
            indexString.append('\u0022'+i+'\u0022' +":" +"{ \"type\": \"keyword\",\"normalizer\": \"testnormalizer\"}" + ",");

        }
        indexString.delete(indexString.length()-1, indexString.length()).append("}}}}");

        indexQuery = indexString.toString();
        logger.info("index query is " + indexQuery);
        CreateIndexRequest request = new CreateIndexRequest(tableName);
        request.source(indexQuery, XContentType.JSON);
        
        CreateIndexResponse createIndexResponse= restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);

while printing the query before calling restHighLevel client :

index query is

{"settings": {"max_result_window":10000000,"keyspace":"ndl","analysis": {"normalizer":{"testnormalizer": {"type": "custom","char_filter": [],"filter": ["asciifolding"]}}}},"mappings":{"initest2":{"discover" : ".*","properties":{"name":{ "type": "keyword","normalizer": "testnormalizer"}}}}}

Please assist if any method to be updated in java code / any properties to be updated in elassandra

Current versrion of elasticsearch : 6.8.4

Note : tried using request.settings() & request.mappings() but it didnt help

3
  • The "initest2":{"discover" : ".*", looks wrong to me
    – Val
    Dec 14, 2022 at 14:30
  • removed discover filed and tested , still facing the issue .. Can u please guide on what can be checked further .. is there any method to check whether index mapping is empty or not once index is created
    – mpsimham
    Dec 15, 2022 at 12:28
  • getting this exception if we remove discover .... but table is craeted properly with text type Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to execute query:null : Existing column [name] type [text] mismatch with inferred type [list<text>]]]; nested: ElasticsearchException[Elasticsearch exception [type=configuration_exception,
    – mpsimham
    Dec 19, 2022 at 3:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.