'SpringBootData ElasticSearch cannot create index on non-indexed field
I'm struggling creating a Document with field that are specified to be analyzed by ElasticSearch. I'm using Spring Data Elasticsearch version 4.1.6.
This is my Entity
@Document(indexName = "employee-info")
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class EmployeeInfo {
@Id
@Field(type = FieldType.Keyword)
private String empNo;
@Field(type = FieldType.Keyword)
private String pinCd;
@Field(type = FieldType.Text)
private String empNm;
@Field(index = false)
private String fullDeptCd;//00082;N0001;N0002;N0060;LW00002289;LW00002384;LW00002501",
// ... other fields
}
Upon Bootstrapping, it logs:
2022-03-09 13:03:22,477 WARN [main] SimpleElasticsearchRepository.java:96: Cannot create index: Elasticsearch exception [type=mapper_parsing_exception, reason=No type specified for field [fullDeptCd]]; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=No type specified for field [fullDeptCd]]]
and the mapping:
{
"mappings": {
"_doc": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"empNo": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"fullDeptCd": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
...
- Why
empNoistextbut itsfieldsarekeywordand it also doesn't haveindex? - Why
fullDeptCdmapping is exactly the same asempNo?
What I understand:
FieldType.Keyword: this field will not be tokenized, but it is still indexed by default.FieldType.Text: this field will be tokenized by the analyzer.index = false: do not analyzed and index this field.
I feel like it's very difficult to work with ElasticSearch with SpringBoot, a lot of property in @Field annotation are not documented and I don't know how to use them properly.
If you have experience with ElasticSearch, please help.
Thank you in advance.
Solution 1:[1]
Looks like for some reason, the default FieldType.Auto not working, I have to explicitly specify type for all fields.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Loc Truong |
