這個問題也困擾了我很久,網上關于這方面的確實資料很少,不過還是解決了,官方檔案還是靠譜。
主要原因是資料模型的配置,使用spring-data-elasticsearch時候我們一般都是默認配置,問題就出在這里,默認配置中的資料模型使用的是Jackson Object Mapping,在使用這種資料模型時候,@Field是不起作用的。
這時候就用到了另一種資料模型映射(Meta Model Object Mapping),這種映射支持欄位的詳細配置,具體配置參看官網鏈接 ,這里貼出@field的部分配置。
@Field: Applied at the field level and defines properties of the field, most of the attributes map to the respective Elasticsearch Mapping definitions:
name: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used.
type: the field type, can be one of Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword.
format and pattern custom definitions for the Date type.
store: Flag wether the original field value should be store in Elasticsearch, default value is false.
analyzer, searchAnalyzer, normalizer for specifying custom custom analyzers and normalizer.
copy_to: the target field to copy multiple document fields to.
最后總結解決方案:
1. 添加組態檔
@Configuration
public class Config extends AbstractElasticsearchConfiguration {
@Override
public RestHighLevelClient elasticsearchClient() {
return RestClients.create(ClientConfiguration.create("localhost:9200")).rest()
}
@Bean
@Override
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(
elasticsearchMappingContext(), new DefaultConversionService()
);
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
}
2. 在欄位上使用注解
@Field(type = FieldType.Text, name="src_ip")
private String srcIp;
uj5u.com熱心網友回復:
name屬性是不是只有高版本才有
uj5u.com熱心網友回復:
我使用這個API一般都是使用最新版,這個沒有找到像ES那樣詳細到各個版本都分類好的檔案
uj5u.com熱心網友回復:
這個問題也困擾了我很久,網上關于這方面的確實資料很少,不過還是解決了,官方檔案還是靠譜。
主要原因是資料模型的配置,使用spring-data-elasticsearch時候我們一般都是默認配置,問題就出在這里,默認配置中的資料模型使用的是Jackson Object Mapping,在使用這種資料模型時候,@Field是不起作用的。
這時候就用到了另一種資料模型映射(Meta Model Object Mapping),這種映射支持欄位的詳細配置,具體配置參看官網鏈接 ,這里貼出@field的部分配置。
@Field: Applied at the field level and defines properties of the field, most of the attributes map to the respective Elasticsearch Mapping definitions:
name: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used.
type: the field type, can be one of Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword.
format and pattern custom definitions for the Date type.
store: Flag wether the original field value should be store in Elasticsearch, default value is false.
analyzer, searchAnalyzer, normalizer for specifying custom custom analyzers and normalizer.
copy_to: the target field to copy multiple document fields to.
最后總結解決方案:
1. 添加組態檔
@Configuration
public class Config extends AbstractElasticsearchConfiguration {
@Override
public RestHighLevelClient elasticsearchClient() {
return RestClients.create(ClientConfiguration.create("localhost:9200")).rest()
}
@Bean
@Override
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(
elasticsearchMappingContext(), new DefaultConversionService()
);
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
}
2. 在欄位上使用注解
@Field(type = FieldType.Text, name="src_ip")
private String srcIp;
眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......
值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......