I am using phonetic analyzer .json file
search-analyzer.json
{
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_metaphone"
]
}
},
"filter": {
"my_metaphone": {
"type": "phonetic",
"encoder": "double_metaphone",
"replace": false
}
}
}
}
And using the below Entity class and the analyzer.
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Document(indexName = "ABC")
@Setting(settingPath = "analyzer/search-analyzer.json")
@JsonIgnoreProperties(ignoreUnknown = true)
@Slf4j
@EqualsAndHashCode
public class XYZ {
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
@Field(type = FieldType.Text,analyzer = "my_analyzer")
private String firstName;
@Field(type = FieldType.Keyword)
private String middleName;
@Field(type = FieldType.Text,analyzer = "my_analyzer")
private String name;
}
In the BoolQueryBuilder again using combination like the below
if(IsNotEmptyOrNull(Search.getFirstName())){
BoolQueryBuilder boolQueryCombined = QueryBuilders.boolQuery();
boolQueryCombined.should(QueryBuilders.matchQuery(FIRSTNAME, Search.getFirstName()).fuzziness(Fuzziness.AUTO));
boolQueryCombined.should(QueryBuilders.wildcardQuery(FIRSTNAME, Search.getFirstName().toLowerCase().concat("*")));
boolQueryCombined.minimumShouldMatch(1);
boolQueryBuilder.must(boolQueryCombined);
}
where Search is a object containing all search properties like firstName,name ...
Then Fuzzy Auto not working only phonetic match happening. phonetic is overriding the fuzziness?
Will be using EdgeNgram Analyzer instead of Wildcard Query later.