# Why does SearchScript call multiple times?

**URL:** <https://discuss.elastic.co/t/why-does-searchscript-call-multiple-times/108955>\
**Category:** Elasticsearch\
**Created:** [November 24, 2017, 3:50am UTC](https://discuss.elastic.co/t/why-does-searchscript-call-multiple-times/108955 "2017-11-24T03:50:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tavandung12](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@tavandung12](https://discuss.elastic.co/u/tavandung12)\
**Post date:** [November 24, 2017, 3:50am UTC](https://discuss.elastic.co/t/why-does-searchscript-call-multiple-times/108955/1 "2017-11-24T03:50:11Z")

</div>

my source code:

```java
public Function<Map<String, Object>, SearchScript> compile(
    		String scriptName, String scriptSource, Map<String, String> params) {
    	checkScriptSource(scriptSource);
    	logger.info("start compline script name: {}, source: {}", scriptName, scriptSource);
    	return p -> new SearchScriptBuilder()
    			.params(p)
    			.restHighLevelClient(restHighLevelClient)
    			.queryVectoryResearcherFactory(queryVectoryResearcherFactory)
    			.build();
    }

```

```auto
public class SearchScriptBuilder implements BaseBuilder<SearchScript> {
@Override
	public SearchScript build() {
		logger.info("build search script, thread name: {}", Thread.currentThread().getName());
		validateParams();
		return newProduct();
	}
}

```

my logs:

```auto
[2017-11-24T10:43:22,589][INFO][com_tvd12] start compline script name: double_array_similarity, source: double_array_similarity
[2017-11-24T10:43:22,592][INFO][com_tvd12] build search script, thread name: elasticsearch[8iFnvKh][search][T#2]
[2017-11-24T10:43:22,592][INFO][com_tvd12] build search script, thread name: elasticsearch[8iFnvKh][search][T#4]
[2017-11-24T10:43:22,593][INFO][com_tvd12] build search script, thread name: elasticsearch[8iFnvKh][search][T#3]
[2017-11-24T10:43:22,594][INFO][com_tvd12] build search script, thread name: elasticsearch[8iFnvKh][search][T#5]
[2017-11-24T10:43:22,600][INFO][com_tvd12] build search script, thread name: elasticsearch[8iFnvKh][search][T#1]

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 24, 2017, 6:11am UTC](https://discuss.elastic.co/t/why-does-searchscript-call-multiple-times/108955/2 "2017-11-24T06:11:04Z")

</div>

May be because you have more than one shard?

---

<div class="post-metadata">

**Author:** ![tavandung12](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@tavandung12](https://discuss.elastic.co/u/tavandung12)\
**Post date:** [November 24, 2017, 9:04am UTC](https://discuss.elastic.co/t/why-does-searchscript-call-multiple-times/108955/3 "2017-11-24T09:04:03Z")

</div>

Yes, by default, I have 5 primary shards and 1 replica

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 24, 2017, 9:16am UTC](https://discuss.elastic.co/t/why-does-searchscript-call-multiple-times/108955/4 "2017-11-24T09:16:56Z")

</div>

So that's why.

---

<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 22, 2017, 9:17am UTC](https://discuss.elastic.co/t/why-does-searchscript-call-multiple-times/108955/5 "2017-12-22T09:17:03Z")

</div>

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