3

I have elasticsearch entity in spring as below :

@Document(indexName = "cities_in", type = "cities")
public class CityDocument {

@Id
private String id;

@Field(type = FieldType.String)
private String city;

@Field(type = FieldType.Object)
@GeoPointField
private GeoPoint location;
}

but when I see mapping using curl curl -s -XGET 'http://localhost:9200/cities_in/cities/_mapping?pretty=1' I get output as:

  {
   "cities_in" : {
   "mappings" : {
    "cities" : {
      "properties" : {
        "city" : {
          "type" : "string"
        },
        "id" : {
         "type" : "string"
      },
      "location" : {
        "properties" : {
          "geohash" : {
            "type" : "string"
          },
          "lat" : {
            "type" : "double"
          },
          "lon" : {
            "type" : "double"
          }
        }
        }
        }
     }
   }
 }
}

and when hit I query I get below error:

{
 "error" : {
"root_cause" : [ {
  "type" : "query_parsing_exception",
  "reason" : "No query registered for [geo_point]",
  "index" : "cities_in",
  "line" : 1,
  "col" : 33
} ],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [ {
  "shard" : 0,
  "index" : "cities_in",
  "node" : "4jGBH3m4SkqNnBwC196hTw",
  "reason" : {
    "type" : "query_parsing_exception",
    "reason" : "No query registered for [geo_point]",
    "index" : "cities_in",
    "line" : 1,
    "col" : 33
  }
} ]
  },
  "status" : 400
 }

Why is location type not geo_point? How to manage geopoint with spring?

2 Answers 2

6

If you use Spring, make sure thath you use GeoPoint from spring

org.springframework.data.elasticsearch.core.geo.GeoPoint

Sign up to request clarification or add additional context in comments.

Comments

5

The problem is that FieldType.Object fields get processed before @GeoPointField by Spring Data's MapperBuilder.

So you simply need to remove the @Field(type = FieldType.Object) annotation and just declare your location field like this:

@GeoPointField
private GeoPoint location;

5 Comments

Still its working as spring is not creating field type "geo_point". If i am adding mapping using curl and then adding/fetching data from spring its working. May be spring not supporting field type "geo_point"
What version of Spring Data are you using? Have you deleted the index prior to restarting your Spring app?
Thanks a lot, its working now. I was using GeoPoint class "org.elasticsearch.common.geo.GeoPoint" instead of "org.springframework.data.elasticsearch.core.geo.GeoPoint".
@Val can you tell in what case I must use FieldType.Object? Example, I have an Object Client with name and id attributes, I want to store this in elasticsearch just they way it is (with those 2 attributes), but when I run my app I get an error: 'MapperParsingException[object mapping for [cliente] tried to parse field [cliente] as object, but found a concrete value]'
@franzisk This is because your field cliente already exists in the mapping and has another type. You cannot change the type once created, you need to create a new index with the correct type for cliente and then reindex your data

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.