Reputation: 231
I am trying to do a Phrase matching to find similar Phrases.
Eg. Name field has following entries and all 3 should be evaluated to same :
Can you suggest a Java code that uses Phrase matcher or something similar to suggest that above entries in the Name field are same ( possibly higher score)
Thanks.
Upvotes: 0
Views: 1255
Reputation: 1423
You may use match query using "phrase" type or "phrase_prefix" type for your case. In Java client, Elasticsearch provides two kinds of method you can use.
Try to test the scripts below to check the result.
curl -s -XPOST "http://localhost:9200/ap100/example/1" -d '{
"name": "USA Tech Company"
}'
curl -s -XPOST "http://localhost:9200/ap100/example/2" -d '{
"name": "USA Tech Company Alabama"
}'
curl -s -XPOST "http://localhost:9200/ap100/example/3" -d '{
"name": "USA Tech Company California"
}'
curl -XGET "http://localhost:9200/ap100/example/_search?pretty" -d '{
"query":{
"match":{
"name": {
"type": "phrase",
"query": "usa tech company",
"slop": 2
}
}
}
}'
curl -XGET "http://localhost:9200/ap100/example/_search?pretty" -d '{
"query":{
"match":{
"name": {
"type": "phrase_prefix",
"query": "usa tech company"
}
}
}
}'
Upvotes: 1