Search code examples
spring-bootspring-dataspring-data-elasticsearchelasticsearch-6custom-data-type

Spring Data Elasticsearch Problem with IP_Range Data type


I use Spring boot 2.0.1.RELEASE/ Spring Data Elasticsearch 3.0.6. I annotate my domain class with @Document annotation and i have a field as below:

@Field(store = true, type = FieldType.?)
private String ipRange;

as you see, I need to set the field type to IP_Range (exists in elastic search engine data types) but not exists in FieldType enum.

I want to create this document index by ElasticsearchTemplate.createIndex(doc) method. but none of any FieldType enum support ip_range data type.


Solution

  • Thanks @P.J.Meisch for your reply, I used @Mapping annotation to specify my mapping directly via json format. Already Spring data supports creating index based on this config. but i am also waiting for Range Data Structure Support to refactor my code.

    My Document:

    @Document(createIndex = true, indexName = "mydomain", type = "doc-rule"
            , refreshInterval = BaseDocument.REFRESH_INTERVAL, replicas = BaseDocument.REPLICA_COUNT, shards = BaseDocument.SHARD_COUNT)
    @Mapping(mappingPath = "/elasticsearch/mappings/mydomain-mapping.json")
    public class MyDomainDoc {
    
    @Field(store = true, type = FieldType.text)
    private List<String> ipRange;
    
    ... other fields
    
    }
    

    And My mydomain-mapping.json file:

    {
      "properties": {
        ...,
        "ipRange": {
          "type": "ip_range",
          ...
        },
        ...
      }
    }