Currently I am testing on ES Multi Terms feature. Please find the sample data with indices.
PUT multi_terms_test1
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
PUT multi_terms_test1/_mapping
{
"properties": {
"COUNTRY": {
"type": "keyword"
},
"FIRST_NAME": {
"type": "keyword"
},
"FULL_NAME": {
"type": "keyword"
},
"PAY_DATE": {
"type": "date",
"format": "yyyy-MM-dd"
},
"SALARY": {
"type": "long"
},
"ID": {
"type": "keyword"
}
}
}
PUT multi_terms_test1/_doc/1
{
"ID": "1",
"COUNTRY": "USA",
"FIRST_NAME": "John",
"FULL_NAME":"John B",
"PAY_DATE":"2022-02-15",
"SALARY":1200
}
PUT multi_terms_test1/_doc/2
{
"ID": "1",
"COUNTRY": "Nepal",
"FIRST_NAME": "Suresh",
"FULL_NAME":"Suresh G",
"PAY_DATE":"2022-12-31",
"SALARY":1000
}
PUT multi_terms_test1/_doc/3
{
"ID": "1",
"COUNTRY": "France",
"FIRST_NAME": "Michel",
"FULL_NAME":"Michel J",
"PAY_DATE":"2022-08-09",
"SALARY":1500
}
PUT multi_terms_test2
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
POST _aliases
{
"actions": [
{
"add": {
"index": "multi_terms_test1",
"alias": "multi_terms"
}
},
{
"add": {
"index": "multi_terms_test2",
"alias": "multi_terms"
}
}
]
}
Note:
- multi_terms_test1 is with mapping
- multi_terms_test2 is without mapping
From the above request, we had created multi_terms_test1 and multi_terms_test2 index pointing with multi_terms alias.
Now we are quering on alias (i.e. multi_terms) as shown below:
GET multi_terms/_search
{
"size": 0,
"aggs": {
"country_pay_date": {
"multi_terms": {
"terms": [
{
"field": "COUNTRY"
},
{
"field": "PAY_DATE"
}
],
"order": {
"_key": "desc"
},
"size":7
}
}
}
}
As multi_terms_test1 contains mapping but multi_terms_test2 doesnot contain mapping, we got following exception.
Exception:
Merging/Reducing the multi_term aggregations failed when computing the aggregation country_pay_date because the field in the position 2 in the aggregation has two different types in two different indices
But If i run the query on multi_terms_test1 index, we got the result as shown below:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"country_pay_date": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": [
"USA",
"2022-02-15"
],
"key_as_string": "USA|2022-02-15",
"doc_count": 1
}
]
}
}
}
And executing on multi_terms_test2 index result empty result as shown below:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"country_pay_date": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
}
Question:
- Do we need to have mapping in all index for multi terms?
- Why multi terms works on quering single index without mapping one?
- Is there any other parameter (like ignore_unmapped) need to be added in ES Query?
OR
Is this known issue in Elasticsearch itself?
Tested ES Version: 7.16 and 8.6
Thank you inadvance.