# Restrict suggestions to provide data from an desired index while using stored searches

**URL:** <https://discuss.elastic.co/t/restrict-suggestions-to-provide-data-from-an-desired-index-while-using-stored-searches/286498>\
**Category:** Elasticsearch\
**Created:** [October 12, 2021, 1:24pm UTC](https://discuss.elastic.co/t/restrict-suggestions-to-provide-data-from-an-desired-index-while-using-stored-searches/286498 "2021-10-12T13:24:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcvijayvignesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pcvijayvignesh/32/95746_2.png) [@pcvijayvignesh](https://discuss.elastic.co/u/pcvijayvignesh)\
**Post date:** [October 12, 2021, 1:24pm UTC](https://discuss.elastic.co/t/restrict-suggestions-to-provide-data-from-an-desired-index-while-using-stored-searches/286498/1 "2021-10-12T13:24:44Z")

</div>

We are using stored searches to perform queries, sort, agregations, and suggestions across a predefined index.

Previously, we were not able to restrict the sort to certain indexes, so when we do a sort it searched across all the indexes, and the index without having the sort field showed an error like below.

```auto
"reason": {
	"type": "illegal_argument_exception",
	"reason": "no mapping found for field [firstname]"
}

```

We looked through the documentation ( [\_index field | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html)) and fixed it by passing the sort param (\_index ) like below.

```auto
"sort": [
	{
		"_index": { 
	        "order": "asc"
	    },
		"firstname": {
			"order": "desc"
		}
	}
]

```

Similarly, we have suggestions configured in our stored search, however, we are not able to restrict them to the desired index. Is there any way to achieve the same on suggestions?

```auto
{
    "suggest": {
        "Suggestion": {
            "text": "*",
            "phrase": {
                "analyzer": "trigram",
                "field": "suggest_field",
                "size": 1,
                "real_word_error_likelihood": 0.95,
                "confidence": 1,
                "separator": " ",
                "max_errors": 4,
                "gram_size": 3,
                "force_unigrams": true,
                "token_limit": 10,
                "direct_generator": [
                    {
                        "field": "suggest_field",
                        "max_edits": 2,
                        "max_inspections": 5,
                        "max_term_freq": 0.01,
                        "min_word_length": 4,
                        "min_doc_freq": 5,
                        "prefix_length": 4,
                        "suggest_mode": "MISSING",
                        "size": 1
                    }
                ]
            }
        }
    }
}

```

---

<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:** [November 9, 2021, 1:24pm UTC](https://discuss.elastic.co/t/restrict-suggestions-to-provide-data-from-an-desired-index-while-using-stored-searches/286498/2 "2021-11-09T13:24:49Z")

</div>

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