# Multiterms on multi index

**URL:** <https://discuss.elastic.co/t/multiterms-on-multi-index/340519>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [August 10, 2023, 7:47am UTC](https://discuss.elastic.co/t/multiterms-on-multi-index/340519 "2023-08-10T07:47:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suresh\_Ghatuwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_ghatuwa/32/99976_2.png) [@Suresh\_Ghatuwa](https://discuss.elastic.co/u/Suresh_Ghatuwa)\
**Post date:** [August 10, 2023, 7:47am UTC](https://discuss.elastic.co/t/multiterms-on-multi-index/340519/1 "2023-08-10T07:47:46Z")

</div>

Currently I am testing on ES Multi Terms feature. Please find the sample data with indices.

```auto
PUT multi_terms_test1
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

```

```auto
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"
    }
  }
}

```

```auto
PUT multi_terms_test1/_doc/1
{
  "ID": "1",
  "COUNTRY": "USA",
  "FIRST_NAME": "John",
  "FULL_NAME":"John B",
  "PAY_DATE":"2022-02-15",
  "SALARY":1200
}

```

```auto
PUT multi_terms_test1/_doc/2
{
  "ID": "1",
  "COUNTRY": "Nepal",
  "FIRST_NAME": "Suresh",
  "FULL_NAME":"Suresh G",
  "PAY_DATE":"2022-12-31",
  "SALARY":1000
}

```

```auto
PUT multi_terms_test1/_doc/3
{
  "ID": "1",
  "COUNTRY": "France",
  "FIRST_NAME": "Michel",
  "FULL_NAME":"Michel J",
  "PAY_DATE":"2022-08-09",
  "SALARY":1500
}

```

```auto
PUT multi_terms_test2
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

```

```auto
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:

```auto
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:

```auto
{
  "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:

```auto
{
  "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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 7, 2023, 7:48am UTC](https://discuss.elastic.co/t/multiterms-on-multi-index/340519/2 "2023-09-07T07:48:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
