Basically using the below is bringing only phonetically match value fuzziness(Fuzziness.AUTO) not working if I use phonetic analyzer json file as mentioned above.
boolQueryCombined.should(QueryBuilders.matchQuery(FIRSTNAME, partySearch.getFirstName()).fuzziness(Fuzziness.AUTO));
boolQueryCombined.should(QueryBuilders.wildcardQuery(FIRSTNAME, partySearch.getFirstName().toLowerCase().concat("*")));
Data Inserted
anju
manju
Phonetic Result for double_metaphone search with manju
manju (Not working if we use phonetic analyzer)
Fuzzy Result for double_metaphone search with manju
anju
manju
What is the output of the _analyzer API with your texts?
That's the way to check how the analyzer behaves at index time and search time.
If you need more help, it would help a lot to create a minimal reproduction script we can easily copy/paste into the dev console and iterate from there.
http://localhost:9200/xyz/_analyze
input :
{
"tokenizer": "standard",
"filter": [
"lowercase",
"my_metaphone"
],
"text": "manju"
}
output:
{
"tokens": [
{
"token": "manju",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "MNJ",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 0
}
]
}
Analyzer working fine with encoder like double_metaphone,soundex :+1:
But this same thing when combined with fuzziness the fuzziness is not working in the bool query is the question ???.
Both Fuzzy and phonetic match would be there together. Phonetic behavior through
encoders and Fuzzy through bool query as mentioned in the above comments is expected.
It would help to reproduce with a minimal script so we can really understand what the problem is and what you are doing.
I am not using analyzer in the second table its plain bool query with getFirstName()).fuzziness(Fuzziness.AUTO) where fuzziness is working fine but in the 1st table I need both phonetic(analyzer) and fuzzy, where fuzziness is not working.
Well... As you are querying firstName, I think the analyzer of this field is applied.
Ok let me break it down.
Two table are there one with phonetic analyzer and one without phonetic analyzer .
1) Table XYZ (Phonetic)
2) Table ABC
XYZ Table with install analysis-phonetic already done for phonetic match.
ABC Table not analyzed.
For Table XYZ(Phonetic + Fuzzy ) is the requirement and this fuzzy is not working only Phonetic working.
@AllArgsConstructor
@NoArgsConstructor
@Data
@Document(indexName = "XYZ ")
@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.Text,analyzer = "my_analyzer")
private String name;
}
search-analyzer.json
{
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_metaphone"
]
}
},
"filter": {
"my_metaphone": {
"type": "phonetic",
"encoder": "double_metaphone",
"replace": false
}
}
}
}
Using Bool QueryBuilder I writing java code to build query and hit XYZ Table where
fuzziness(Fuzziness.AUTO) is not working on phonetic behaviour is working.
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);
For Table ABC ( Fuzzy ) is the requirement and this is working
@AllArgsConstructor
@NoArgsConstructor
@Data
@Document(indexName = "ABC")
@JsonIgnoreProperties(ignoreUnknown = true)
@Slf4j
@EqualsAndHashCode
public class ABC {
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
@Field(type = FieldType.Text")
private String firstName;
@Field(type = FieldType.Text")
private String name;
}
Using Bool QueryBuilder I writing java code to build query and hit ABC Table where
fuzziness(Fuzziness.AUTO) is working. Same code as above.
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);
Data Inserted for XYZ,ABC Table
anju
manju
Phonetic Result for double_metaphone search with manju as search criteria in XYZ Table
manju
Fuzzy Result for double_metaphone search with manju as search criteria in ABC Table
anju
manju
***XYZ Table should give same result as ABC as in both case fuzziness(Fuzziness.AUTO))
is given ***
****** I think a if we putting phonetic analyzer it not considering that column for fuzzy search. ******
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.