I trying to add a new field (bioAuto) to existed index (users). I have POJO for this index:
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;
import java.time.LocalDateTime;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = IndexName.USERS)
@Setting(settingPath = "elastic/autocomplete_settings.json")
public class User {
@Id
private Long id;
@Field(type = FieldType.Search_As_You_Type)
private String userName;
@Field(type = FieldType.Text, analyzer = "autocomplete_whitespace_only", searchAnalyzer = "autocomplete_search")
private String bioAuto;
}
Field created, but type is wrong, it doesn't connected with my custom analyzers (defined in elastic/autocomplete_settings.json).
Created field type:
"bioAuto" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
Right field type:
"bioAuto" : {
"type" : "text",
"analyzer" : "autocomplete_whitespace_only",
"search_analyzer" : "autocomplete_search"
},
If I re-create my index (remove users index and run the application one more time), everything works fine. ElasticCloud: 7.9.3, Spring Data version: 4.2.6
P.S. If I execute this command, everything also works fine, the problem in automatic field creation with right type in Spring Data Elastic
PUT /users/_mapping
{
"properties": {
"bioAuto" : {
"type" : "text",
"analyzer" : "autocomplete_whitespace_only",
"search_analyzer" : "autocomplete_search"
}
}
}