# Termsの上限数について

**URL:** <https://discuss.elastic.co/t/terms/107324>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [November 13, 2017, 3:37am UTC](https://discuss.elastic.co/t/terms/107324 "2017-11-13T03:37:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoshiro](https://avatars.discourse-cdn.com/v4/letter/y/5e9695/32.png) [@yoshiro](https://discuss.elastic.co/u/yoshiro)\
**Post date:** [November 13, 2017, 3:37am UTC](https://discuss.elastic.co/t/terms/107324/1 "2017-11-13T03:37:47Z")

</div>

termsで1024件を超えた数を指定した場合に、下記のエラーが発生しました。

リクエスト

```
GET /xxxxxx/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "xxxx_id": [
                # ここに大量のID
            ]
         }
      ]
    }
  }
}

```

レスポンス

```
{
  "error": {
    "root_cause": [
      {
        "type": "too_many_clauses",
        "reason": "too_many_clauses: maxClauseCount is set to 1024"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    ...略
}

```

古い情報ですが、下記のディスカッションではtermsを使えば1024件を超えても可能だといったことが書かれていました。

> [@How do I get Elasticsearch max\_clause\_count to take effect?](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133):
>
> I am currently setting the max\_clause\_count at the creation of my index as follows: "index":{ "type" :"new", "bulk\_size":"100000", "bulk\_timeout":"1000ms", "query":{ "bool":{ "max\_clause\_count": 1000000 } } } The setting is refelected when I check my index settings at [http://localhost:9200/myindex/\_settings](http://localhost:9200/myindex/_settings) with this line: index.query.bool.max\_clause\_count: "1000000" Despite this, when I run a query, I get the below error stating that the max\_clause\_count is the default 1024: Ca…

これは仕様が変わったということでしょうか。

実際に1024件を超えた場合はどうするのが推奨されているでしょうか。  
現状は、1024件ずつに切って、Multi Searchで検索するつもりでいますが、これが最適なのか分からず質問させていただきました。

> **[Multi search API | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)**

ご教授、よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![yoshiro](https://avatars.discourse-cdn.com/v4/letter/y/5e9695/32.png) [@yoshiro](https://discuss.elastic.co/u/yoshiro)\
**Post date:** [November 13, 2017, 6:09am UTC](https://discuss.elastic.co/t/terms/107324/2 "2017-11-13T06:09:12Z")

</div>

自己解決しました。

must ではなく、 filterを使うべきでした。

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [November 16, 2017, 6:25am UTC](https://discuss.elastic.co/t/terms/107324/3 "2017-11-16T06:25:56Z")

</div>

そもそもとしては、どうしてそのように多くのIDを条件に指定して検索しないといけないかなどをもう一度見直すのもいいかと思います。

---

<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:** [December 14, 2017, 6:25am UTC](https://discuss.elastic.co/t/terms/107324/4 "2017-12-14T06:25:58Z")

</div>

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