# Context Suggester is very slow for large context set

**URL:** <https://discuss.elastic.co/t/context-suggester-is-very-slow-for-large-context-set/233048>\
**Category:** Elasticsearch\
**Created:** [May 18, 2020, 7:24am UTC](https://discuss.elastic.co/t/context-suggester-is-very-slow-for-large-context-set/233048 "2020-05-18T07:24:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![raychow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raychow/32/68530_2.png) [@raychow](https://discuss.elastic.co/u/raychow)\
**Post date:** [May 18, 2020, 7:24am UTC](https://discuss.elastic.co/t/context-suggester-is-very-slow-for-large-context-set/233048/1 "2020-05-18T07:24:08Z")

</div>

Hi,

I'm considering to use context suggester to auto complete user input, and the context is used as permission scope:

```auto
PUT localhost:9200/multi_conditions_2?pretty
Content-Type: application/json

{
  "mappings": {
    "properties": {
      "permission_scope": {
        "type": "keyword"
      },
      "id_search": {
        "type": "text",
        "fields": {
          "suggest": {
            "type": "completion",
            "contexts": [
              {
                "name": "permission_scope",
                "type": "category",
                "path": "permission_scope"
              }
            ]
          }
        }
      }
    }
  }
}

```

Since one user may have many permissions, I found that the speed of context suggester slowed down significantly as the number of search contexts increased:

```auto
{
  "_source": "id_search",
  "suggest": {
    "id_search": {
      "text": "sg-",
      "completion": {
        "field": "id_search.suggest",
        "skip_duplicates": true,
        "contexts": {
          "permission_scope": [
            "123456789.permission1.sub-permission1.leaf-permission1",
            "123456789.permission2.sub-permission1.leaf-permission1",
            "123456789.permission3.sub-permission1.leaf-permission1",
            "123456789.permission4.sub-permission1.leaf-permission1",
            "123456789.permission5.sub-permission1.leaf-permission1",
            ... (200 contexts in total)
            "123456789.permission200.sub-permission1.leaf-permission1"
          ]
        }
      }
    }
  }
}

```

When the number of search contexts exceeds a certain threshold, the search fails and returns an error such as:

```auto
{
  "type": "too_complex_to_determinize_exception",
  "reason": "Determinizing automaton with 42901 states and 44900 transitions would result in more than 10000 states."
}

```

Is there any solution to avoid this error and speed up the query?

---

<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:** [June 15, 2020, 7:24am UTC](https://discuss.elastic.co/t/context-suggester-is-very-slow-for-large-context-set/233048/2 "2020-06-15T07:24:09Z")

</div>

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