I'm trying to execute a term query on a keyword field and I am receiving no results. If I remove the keyword the query returns the expected results.
GET myindex/_search
{
"query": {
"term": {
"creatorId.keyword": "c29dae46-23bd-4349-b989-f6bb803b1dd8"
}
}
}
This is the mapping shown under my index mappings for that particular field:
"creatorId": {
"type": "keyword"
}
I would like to know why this is happening and how can I make the keyword work here.
You have already defined that your field is of the keyword type. This way you don't need to make it explicit in the query. Just use pure field. You would just use .keyword if the field is mapped like this:
"mappings": {
"properties": {
"creatorId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}