2

I have a simple ES document that is annotated with Spring elastic search:

@Document(indexName = "indexName", type = "metadata")
public class EsMetadata {

    @Id
    @NonNull
    @Field(type = FieldType.keyword)
    String metadataId;

    @NonNull
    @Field(type = FieldType.keyword)
    String assetId;
}

Those two strings usually are represented by a UUID string, which includes hyphens. When trying to search for a specific UUID i run into this problem mentioned here: Elastic Search Hyphen issue with term filter

The solution (or workaround) is to set the FieldType to keyword works on the assetId field, but not on the metadataId field - apparently because it is marked as @Id.

When I call this.esTemplate.putMapping(EsMetadata.class) I get a few IllegalArgumentExceptions:

Caused by: java.lang.IllegalArgumentException: Could not convert [metadataId.index] to boolean
Caused by: java.lang.IllegalArgumentException: Failed to parse value [not_analyzed] as only [true] or [false] are allowed.

I use 9515882b-f583-4675-bc19-44c9247c0365 and bc205f3e-35c2-f583-835c-344a9f89d758 as sample UUIDs where parts are equal to correctly test the desired behaviour.

When I remove the @Field(type = FieldType.keyword) annotation from metadataId, everything works fine - except that I get duplicates upon searching for specific metadataId UUIDs. For assetId UUIDs there are no duplicates - as expected.

How can I use the keyword FieldType on an @Id annotated field, so i can look up specific UUIDs? Or did I run into a bug?

I use spring-data-elasticsearch 3.1.0.M1 and Elasticsearch 6.2.2

Boris Prohaska
  • 912
  • 6
  • 16

0 Answers0