Reputation: 29
I have indexed few resume in elastic search. So when I am searching for text basically employeeid : "IIIPL-4309". It is giving result for all "IIIPL-xxxx". How can I restrict the search result to just "IIIPL-4309?
I have tried with custom analyzer
Upvotes: 1
Views: 1310
Reputation: 7649
In case you want to search with exact match you should go with Term Query on the keyword field like this
GET /_search
{
"query": {
"term": {
"someField.keyword": {
"value": "IIIPL-4309"
}
}
}
}
Upvotes: 0
Reputation: 8860
What you are looking for is exact match
. You would need to use keyword
type in elasticsearch in order to achieve that.
From the link,
They are typically used for filtering (Find me all blog posts where status is published), for sorting, and for aggregations. Keyword fields are only searchable by their exact value.
Below is how the mapping would be, I'm just creating a sibling field for the employee_id
as employee_id.keyword
PUT employee
{
"mappings":{
"properties":{
"employee_id":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword"
}
}
}
}
}
}
POST employee/_doc/1
{
"employee_id": "IIIPL-4309"
}
POST employee/_doc/2
{
"employee_id": "IIIPL-4229"
}
POST employee/_search
{
"query": {
"term": {
"employee_id.keyword": "IIIPL-4309"
}
}
}
Hope this helps!
Upvotes: 1