Fuzzy search
Procedure to integrate elastic search for Fuzzy search with any of the eGov modules.
Creating the index as per the requirement:
The elastic index has to be used for fuzzy search due to performance enhancement and when PII fields are involved which cannot be accessed in DB directly to apply fuzzy logic.
When PII data are involved those fields shouldn’t be returned by the elastic search but only can be used to apply the filter. To enable this that particular field should be indexed but not stored.
eg -
{
"mappings": {
"general": {
"_source": {
"excludes": [
"name"
]
},
"properties": {
"id": {
"type": "text"
},
"dob": {
"type": "date"
},
"name": {
"type": "text"
}
}
}
}
}
In the above example, when data is posted, all the fields will be stored, but the index will never return the excluded source fields when searched.
Querying an index:
curl --location --request GET 'localhost:9200/_search?pretty' \
--header 'Content-Type: application/json' \
--data-raw '{
"query": {
"fuzzy": {
"name": {
"value": "ki"
}
}
}
}'
This is a simple request, there are additional parameters that can be used to enhance the fuzzy search.
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"fuzzy": {
"name": {
"value": "ki",
"fuzziness": "AUTO",
"max_expansions": 50,
"prefix_length": 0,
"transpositions": true
}
}
}
}
'
Elastic Integration with code:
Add the elasticsearch host from the eGov cluster.
Divide the search params between the ones that will be sent to elastic and others to DB (search to elastic should be made only if the fuzzy fields are present in search request)
The result of the elastic search should be only the required primary-Id of the entity(property-id, trade license-id, etc..)
Then the resulting ids should be used in the normal search as it is.
Please refer to the following commit for the integration
Application properties:
Properties need to add for integration
The indices need to be reindexed for the fuzzy search to work if changes are done in the index. particularly in the case of protected fields being indexed but not to be returned in the search.
Reindexing for PT: Refer here