Home > Back-end >  Spring - data - elasticsearch elasticsearch inquiry with the index of the underline how to deal with
Spring - data - elasticsearch elasticsearch inquiry with the index of the underline how to deal with

Time:09-30

Such as the pres_rq field.

Entity class using the @ JsonProperty tags, test can get to the value, can also values into the es, but as a condition for the query, if use findAllByPresRq unable to query
If use findAllByPres_Rq complains

CodePudding user response:

This problem has troubled me for a long time, really little information about this online, but still settled, or on the official document,
Configuration of the main reason is that the data model, using the spring - data - we generally elasticsearch is the default configuration, that's the problem, the default configuration is used in the data model Jackson Object Mapping, when using this data model, @ Field is not effective,
At this time another data Model is used to map (Meta Model Object Mapping), the detailed configuration of this kind of Mapping support field, specific configuration see website links, posted here @ the part of the configuration of the field,
@ Field: Applied at the Field level and defines the 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 2.
Type: the field type, can be one of the Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword.
The format and the pattern the custom definitions for the Date type.
Store: Flag wether the the original field value should be store in Elasticsearch, the 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.

Finally summarizes the solution:
1. Add the configuration file
@ Configuration
Public class Config extends AbstractElasticsearchConfiguration {
@ Override
Public RestHighLevelClient elasticsearchClient () {
Return RestClients. Create (ClientConfiguration. Create (" localhost: 9200 ")). The rest ()
}
@ Bean
@ Override
Public EntityMapper EntityMapper () {
ElasticsearchEntityMapper entityMapper=new ElasticsearchEntityMapper (
ElasticsearchMappingContext (), new DefaultConversionService ()
);
EntityMapper. SetConversions (elasticsearchCustomConversions ());
Return entityMapper;
}
}
2. Use annotations on the field
@ Field (type=FieldType. Text, name="src_ip)
Private String srcIp;

CodePudding user response:

refer to 6th floor drink the cat's reply:
this problem has troubled me for a long time, really little information about this online, but still settled, or on the official document,
Configuration of the main reason is that the data model, using the spring - data - we generally elasticsearch is the default configuration, that's the problem, the default configuration is used in the data model Jackson Object Mapping, when using this data model, @ Field is not effective,
At this time another data Model is used to map (Meta Model Object Mapping), the detailed configuration of this kind of Mapping support field, specific configuration see website links, posted here @ the part of the configuration of the field,
@ Field: Applied at the Field level and defines the 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 2.
Type: the field type, can be one of the Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword.
The format and the pattern the custom definitions for the Date type.
Store: Flag wether the the original field value should be store in Elasticsearch, the 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.

Finally summarizes the solution:
1. Add the configuration file
@ Configuration
Public class Config extends AbstractElasticsearchConfiguration {
@ Override
Public RestHighLevelClient elasticsearchClient () {
Return RestClients. Create (ClientConfiguration. Create (" localhost: 9200 ")). The rest ()
}
@ Bean
@ Override
Public EntityMapper EntityMapper () {
ElasticsearchEntityMapper entityMapper=new ElasticsearchEntityMapper (
ElasticsearchMappingContext (), new DefaultConversionService ()
);
EntityMapper. SetConversions (elasticsearchCustomConversions ());
Return entityMapper;
}
}
2. Use annotations on the field
@ Field (type=FieldType. Text, name="src_ip)
Private String srcIp;


Name property is only available in the high version

CodePudding user response:

refer to 7th floor leaf, reply:
Quote: refer to the sixth floor drink the cat's reply:

This problem has troubled me for a long time, really little information about this online, but still settled, or on the official document,
Configuration of the main reason is that the data model, using the spring - data - we generally elasticsearch is the default configuration, that's the problem, the default configuration is used in the data model Jackson Object Mapping, when using this data model, @ Field is not effective,
At this time another data Model is used to map (Meta Model Object Mapping), the detailed configuration of this kind of Mapping support field, specific configuration see website links, posted here @ the part of the configuration of the field,
@ Field: Applied at the Field level and defines the 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 2.
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related