How to put mapping by JAVA API

hi, guys

I met a problem that blockde me several days.

I want to put mapping for a field by JAVA API but failed. Following is detailded information:

My data struction is :
"mje-test-execution-id": "464b66ea6c914ddda217659c84a3cb9d",
"jvm-free-memory": 315245608,
"jvm-total-memory": 361758720,
"system-free-memory": 0,
"jvm-max-memory": 7600078848,
"system-total-memory": 34199306240,
"memory-time-stamp": "2020-03-12T05:12:16.835Z",
"mje-host-name": "CN-00015345",
"mje-test-suite-name": "SCF Test no mje version",
"mje-version": "1.8.7771-SNAPSHOT",
"mje-test-artifact-id": "msran-regression-tests",
"mje-test-version": "1.8.7771-SNAPSHOT",
"stp-id": "vran-stp"
"mje-test-location": {
"lat": 58.41,
"lon": 15.62
What I want to do is : put "mje-test-location" type to be "geo_point"

My code snippet :

public void postMapping(String indexName, String field, String type) throws IOException {
GetIndexRequest request = new GetIndexRequest(indexName);

    boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);
    if (!exists) {"index {} does not exist. Now to post mapping.", indexName);
        PutMappingRequest putMappingRequest = new PutMappingRequest(indexName);
        XContentBuilder builder = XContentFactory.jsonBuilder();

                    builder.field("type", type);

        AcknowledgedResponse putMappingResponse = client.indices().putMapping(putMappingRequest,

        boolean acknowledged = putMappingResponse.isAcknowledged();
        if (acknowledged) {
  "Succeed to put mapping: field:{}, type: {}", field, type);
    }"Fail to put mapping due to index {} already exist, ", indexName);

Error info:

15:59:54.397 [main] DEBUG org.elasticsearch.client.RestClient - request [PUT] returned [HTTP/1.1 400 Bad Request]
org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=action_request_validation_exception, reason=Validation Failed: 1: mapping type is missing;]

ElasticSearch JAVA API Version : <>7.0.0</>

I will be grateful if anyone can give me your help.


Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:


This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.