# SearchContext or PreBuiltTransportClient not available in plugin

**URL:** <https://discuss.elastic.co/t/searchcontext-or-prebuilttransportclient-not-available-in-plugin/75949>\
**Category:** Elasticsearch\
**Created:** [February 21, 2017, 8:01pm UTC](https://discuss.elastic.co/t/searchcontext-or-prebuilttransportclient-not-available-in-plugin/75949 "2017-02-21T20:01:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesekstrom](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jamesekstrom](https://discuss.elastic.co/u/jamesekstrom)\
**Post date:** [February 21, 2017, 8:01pm UTC](https://discuss.elastic.co/t/searchcontext-or-prebuilttransportclient-not-available-in-plugin/75949/1 "2017-02-21T20:01:19Z")

</div>

I am trying to upgrade a plugin from 1.\* to 5.\*

Maybe I am doing something wrong here, but this used to work in 1.\*.

We have a script plugin that pulls in results from a different type (child documents), caches them, and returns child document data. There are additional scripts that use the same cached data for range filters or other things on child data.

It would be called like this, for example:

```
"script_fields": {
	"price": {
		"script": {
			"params": {
			"profileId": 4766,
			"index": "icommon",
			"missingValue": 0
			},
			"lang": "native",
			"inline": "get_price"
		}
	}
}

```

Previously, we had access to the search context in the NativeScriptFactory:

```
@Override
public ExecutableScript newScript(@Nullable Map<String, Object> params) {
    final SearchContext searchContext = SearchContext.current();
    ...
    searchContext.searcher().search(new MatchAllDocsQuery(), f, new Collector() {
      ...
    }

```

However, `current()` was removed here [https://github.com/elastic/elasticsearch/commit/9c9afe3f01cf418cf983b4ef1c031f34a728bb12](https://github.com/elastic/elasticsearch/commit/9c9afe3f01cf418cf983b4ef1c031f34a728bb12)

I have tried using the `PreBuiltTransportClient` and passing into the factory, but this requires additional dependencies (I don't think this is the correct approach).

Is searching within a plugin just not supported anymore, or am I missing something?

---

<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:** [March 21, 2017, 8:01pm UTC](https://discuss.elastic.co/t/searchcontext-or-prebuilttransportclient-not-available-in-plugin/75949/2 "2017-03-21T20:01:43Z")

</div>

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