Elasticsearch-mapper 基于注解方式生成mapping(2.0以上)
生活随笔
收集整理的這篇文章主要介紹了
Elasticsearch-mapper 基于注解方式生成mapping(2.0以上)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Elasticsearch生成mapping的方式上有多種方式,我們可以把mapping做成配置文件,也可以用spring-data-elasticsearch基于注解生成。
在基于注解生成這種方式上spring-data的注解還是不錯的,但是如果想深度定制化一些參數spring-data卻是不支持的,比如針對分詞的string類型字段的fielddata加載設置。
又如果項目中不想引入spring但又想使用基于注解方式生成mapping,這時spring-data就不行了,這里有另一種選擇:elasticsearch-mapper
git 地址:http://git.oschina.net/music_code_m/elasticsearch-mapper
elasticsearch-mapper支持絕大部分數據類型和相關參數的設置,使用是請參考官網對各種數據類型和相關參數:ES2.x官網mapping設置
下面是使用示例:
@Document(type = "book", _timestamp = true, _ttl = @TTL(enabled = true, _default = "5m")) public class Book {/*ID,只能是Long或者String類型*/@Idprivate Long id;/*數值類型*/@Field(type = FieldType.Double, ignoreMalformed = true)private Double price;/*數值類型*/@Field(type = FieldType.Integer)private Integer pageCount;/*未分詞String型*/@Field(type = FieldType.String, index = FieldIndex.not_analyzed)private String isnNo;/*bool型*/@Field(type = FieldType.Boolean, nullValue = "false")private Boolean isValid;/*日期類型*/@Field(type = FieldType.Date, format = DateFormat.basic_time_no_millis)private Date publishDate;/*分詞String類型,并設置fielddata加載限制(當然也可不設置用默認)*/@Field(type = FieldType.String,index = FieldIndex.analyzed,analyzer = "ik_max_word",searchAnalyzer = "ik_smart",termVector = TermVector.with_positions_offsets,fielddata = @Fielddata(format = FielddataFormat.paged_bytes,frequency = @FielddataFrequencyFilter(enable = true,min = 0.001,max = 1.2,minSegmentSize = 500),loading = FielddataLoading.eager_global_ordinals))private String author;/*multi field 類型(用于多字段搜索)*/@MultiField(mainField = @Field(type = FieldType.String, index = FieldIndex.analyzed, analyzer = "ik_max_word", searchAnalyzer = "ik_smart"),otherFields = {@MultiNestedField(dotSuffix = "pinyin", nestedField = @Field(type = FieldType.String,index = FieldIndex.analyzed,analyzer = "lc_index",searchAnalyzer = "lc_search")),@MultiNestedField(dotSuffix = "english", nestedField = @Field(type = FieldType.String,index = FieldIndex.analyzed,analyzer = "standard"))})private String title;/*Completion Context Suggester配置(如果不配置CompletionContext則是Completion Suggester)*/@CompletionField(analyzer = "ik", payloads = true, context = {@CompletionContext(name = "bookType", type = CompletionContextType.category, defaultVal = {"algorithm"}),@CompletionContext(name = "bookColor", type = CompletionContextType.category, defaultVal = {"red"})})private String suggestContextField;/*二進制類型*/@Field(type = FieldType.Binary)private byte[] pdf;/*內嵌類型*/@NestedObject(clazz = SalesArea.class)private SalesArea salesArea;}轉載于:https://www.cnblogs.com/chennanlcy/p/6591786.html
總結
以上是生活随笔為你收集整理的Elasticsearch-mapper 基于注解方式生成mapping(2.0以上)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 换行符javajava去除字符串中的空格
- 下一篇: MVC4中EasyUI Tree异步加载