I am learning elasticsearch-7.4.0 and working with basic queries.
I have a product
index which has a field name
with the following mapping:
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
When I am executing the term query to match documents with name "Wine - Ice Wine
".
GET /product/_search
{
"from": 0,
"size" : 1000,
"query": {
"term": {
"name": {
"value": "Wine - Ice Wine"
}
}
}
}
The output I am getting:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
When I am running match query:
GET /product/_search
{
"from": 0,
"size" : 1000,
"query": {
"match": {
"name": "Wine - Ice Wine"
}
}
}
The output I am getting:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 75,
"relation" : "eq"
},
"max_score" : 12.354952,
"hits" : [
{
"_index" : "product",
"_type" : "doc",
"_id" : "403",
"_score" : 12.354952,
"_source" : {
"name" : "Wine - Ice Wine",
"price" : 127,
"in_stock" : 26,
"sold" : 334,
"tags" : [
"Alcohol",
"Wine"
],
"description" : "Nulla neque libero, convallis eget, eleifend luctus, ultricies eu, nibh. Quisque id justo sit amet sapien dignissim vestibulum.",
"is_active" : true,
"created" : "2010/04/12"
}
}
]
}
}
As mentioned, term level queries look for exact match.
So, I am specifying the entire string in the search query.
Both the queries should return the same results.