# Spring Data Elasticsearch with ES 7.2.1 | GeoPoint mapping failure while indexing

**URL:** <https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989>\
**Category:** Elasticsearch\
**Created:** [April 14, 2020, 7:59pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989 "2020-04-14T19:59:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![adivardhan](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@adivardhan](https://discuss.elastic.co/u/adivardhan)\
**Post date:** [April 14, 2020, 7:59pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/1 "2020-04-14T19:59:28Z")

</div>

Hi,

I am using ES 7.2.1 to store large amount of location based data and querying for near-by locations.  
For location coordinates, I am using `GeoPoint` fields from my java codebase.

ES: **7.2.1**  
Spring Data Elasticsearch: **4.0.0.DATAES-690-SNAPSHOT**  
org.elasticsearch: **7.2.1**

Template:

```auto
    curl -X PUT "localhost:9200/_template/store_locator_template?pretty" -H 'Content-Type: application/json' -d'
    {
      "order": 1,
      "index_patterns": [
        "store_locator_*"
      ],
      "settings": {
      },
      "mappings": {
          "properties": {
          "esId": {
            "type": "keyword"
          },
          "geoPoint": {
            "type": "geo_point"
          },
          "storeName": {
            "type": "keyword"
          }
        }
      }
    }

```

Entity class:

```auto
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "esId", callSuper = false)
@NoArgsConstructor
@Document(indexName = "store_locator_index", replicas = 0, createIndex = false)
public class EsEntity {

  @Id
  @Field(type = FieldType.Text)
  private String esId;

  @GeoPointField
  private GeoPoint geoPoint;

  @Field(type = FieldType.Text)
  private String storeName;
}

```

And the code to PUT mapping from Spring:

```auto
//clazz -> entity class with @Document annotation

boolean indexCreated = false;
if (!elasticsearchOperations.indexExists(clazz)) {
    indexCreated = elasticsearchOperations.createIndex(clazz);
}
if (indexCreated) {
    elasticsearchOperations.refresh(clazz);
    elasticsearchOperations.putMapping(clazz); --> Does the MAGIC
}

```

When trying to insert data via **bulkIndex()**, I am getting this error:

`org.springframework.data.elasticsearch.ElasticsearchException: Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages [{QObQeXEBqxAg6uMFyeNZ=ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=**mapper [geoPoint] of different type, current_type [geo_point], merged_type [ObjectMapper]]]**}]`

Also.......  
Everything seems to be working for:  
ES 6.4.3  
Spring Data Elasticsearch 3.1.X

I am able to put mapping (via template) and insert document with GeoPoint.  
The index is generated automatically when doc is inserted via code.  
Here's my template:

```auto
    curl -X PUT "localhost:9200/_template/store_locator_template?pretty" -H 'Content-Type: application/json' -d'
    {
      "order": 1,
      "index_patterns": [
        "store_locator_*"
      ],
      "settings": {
      },
      "mappings": {
        "store_locator_index": {
          "properties": {
          "esId": {
            "type": "keyword"
          },
          "geoPoint": {
            "type": "geo_point"
          },
          "storeName": {
            "type": "keyword"
          }
        }
       }
      }
    }

```

Here's the mapping:

```auto
    {
      "mapping": {
        "properties": {
          "esId": {
            "type": "keyword"
          },
          "geoPoint": {
            "type": "geo_point"
          }
        }
      }
    }

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 15, 2020, 4:59am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/2 "2020-04-15T04:59:40Z")

</div>

May be print / debug the exact json document which is sent to elasticsearch and share it here?

Note that when using springboot with elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your `pom.xml`:

```auto
<properties>
  <elasticsearch.version>7.6.2<elasticsearch.version>
</properties>

```

See documentation here: [https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-customize-dependency-versions](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-customize-dependency-versions)

---

<div class="post-metadata">

**Author:** ![adivardhan](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@adivardhan](https://discuss.elastic.co/u/adivardhan)\
**Post date:** [April 15, 2020, 6:38am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/3 "2020-04-15T06:38:34Z")

</div>

I have not upgraded to 7.6.2 and the cluster nodes I am using are 7.2.1

Also, here's the mapping generated from Spring Data code:

```auto
{
   "esentity":{
      "properties":{
         "esId":{
            "type":"keyword",
            "index":true
         },
         "geoPoint":{
            "type":"geo_point"
         }
      }
   }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 15, 2020, 8:32am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/4 "2020-04-15T08:32:45Z")

</div>

> [@adivardhan](#):
>
> I have not upgraded to 7.6.2 and the cluster nodes I am using are 7.2.1

My answer still applies.

> Note that when using springboot with elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

It would be safe to run `mvn dependency:tree` to check it.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 15, 2020, 8:34am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/5 "2020-04-15T08:34:14Z")

</div>

> [@adivardhan](#):
>
> Also, here's the mapping generated from Spring Data code

I was more asking for the JSON documents that you are indexing. You Javabeans basically but as they are generated as JSON by Spring Data.

---

<div class="post-metadata">

**Author:** ![adivardhan](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@adivardhan](https://discuss.elastic.co/u/adivardhan)\
**Post date:** [April 16, 2020, 5:56am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/6 "2020-04-16T05:56:45Z")

</div>

I was debugging the code, and this is what I suspect is being sent from Spring:

```
{
   "_class":"jp.co.rakuten.elastic.elasticservice.entity.EsEntity",
   "esId":"XbGJgXEBnOE6CQTS9vZM",
   "geoPoint":{
      "lat":33.93468543777032,
      "lon":131.8429772766326
   }
}

```

I think there are converters working in place which convert from a GeoPoint type (when set from Java) into a Map type with 2 keys (lat & lon).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 16, 2020, 7:02am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/7 "2020-04-16T07:02:41Z")

</div>

Could you GET the mapping from elasticsearch? Not the one which is generated by Spring Data but the real one. Something like:

```
GET store_locator_*/_mapping
```

---

<div class="post-metadata">

**Author:** ![adivardhan](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@adivardhan](https://discuss.elastic.co/u/adivardhan)\
**Post date:** [April 16, 2020, 8:56am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/8 "2020-04-16T08:56:56Z")

</div>

> [@adivardhan](#):
>
> I have not upgraded to 7.6.2 and the cluster nodes I am using are 7.2.1

My answer still applies.

I do get a warning in my Java codebase:

**Version mismatch in between Elasticsearch Client and Cluster: 7.6.2 - 7.2.1**

Is this okay to live with?

---

<div class="post-metadata">

**Author:** ![adivardhan](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@adivardhan](https://discuss.elastic.co/u/adivardhan)\
**Post date:** [April 16, 2020, 9:02am UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/9 "2020-04-16T09:02:33Z")

</div>

This is what is generated from Spring Data side and what I can see in the GET mapping API:

```
{
  "store_locator_index": {
    "mappings": {
      "properties": {
        "_class": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "esId": {
          "type": "keyword"
        },
        "geoPoint": {
          "type": "geo_point"
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 17, 2020, 5:23pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/10 "2020-04-17T17:23:52Z")

</div>

So from elasticsearch point of view, if all what you shared is exact, there is nothing wrong.

```auto
DELETE store_locator_index
PUT store_locator_index
{
  "mappings": {
    "properties": {
      "_class": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "esId": {
        "type": "keyword"
      },
      "geoPoint": {
        "type": "geo_point"
      }
    }
  }
}
POST store_locator_index/_doc
{
   "_class":"jp.co.rakuten.elastic.elasticservice.entity.EsEntity",
   "esId":"XbGJgXEBnOE6CQTS9vZM",
   "geoPoint":{
      "lat":33.93468543777032,
      "lon":131.8429772766326
   }
}

```

Gives:

```auto
{
  "_index" : "store_locator_index",
  "_type" : "_doc",
  "_id" : "IiQoiXEBJjDNjw2Cw5no",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

```

Tested on 7.6.1.

So you need to check if what you shared is really the actual mapping and data.  
If it is, you need to ask spring data elasticsearch project probably.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 15, 2020, 5:23pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-with-es-7-2-1-geopoint-mapping-failure-while-indexing/227989/11 "2020-05-15T17:23:55Z")

</div>

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