# PHP Client: Run Indexed Script on Query

**URL:** <https://discuss.elastic.co/t/php-client-run-indexed-script-on-query/53565>\
**Category:** Elasticsearch\
**Created:** [June 21, 2016, 8:12pm UTC](https://discuss.elastic.co/t/php-client-run-indexed-script-on-query/53565 "2016-06-21T20:12:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmccabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmccabe/32/10453_2.png) [@dmccabe](https://discuss.elastic.co/u/dmccabe)\
**Post date:** [June 21, 2016, 8:12pm UTC](https://discuss.elastic.co/t/php-client-run-indexed-script-on-query/53565/1 "2016-06-21T20:12:06Z")

</div>

Does the PHP client support this? Are there any examples of using an indexed script within the query request? All the examples in documentation I can find are inline.

### Code

```php
$scriptScore = new \stdClass(); 
$scriptScore->script = "return _score";
$query = array(
      'function_score' => array(
            'functions' => array(
               array("script_score" => $scriptScore)
            ),
            'query' => $query_string,
         'score_mode' => 'sum',
         'boost_mode' => 'replace'
        )
  );
$params['body']['query'] = $query;

```

The above inline script works and the query results are returned.  
However using a similar method for an indexed script does not work:

```php
$scriptScore = new \stdClass();
$scriptScore->script->id = "indexedScript";
$scriptScore->script->lang = "groovy";
$query = array(
      'function_score' => array(
            'functions' => array(
               array("script_score" => $scriptScore)
            ),
            'query' => $query_string,
         'score_mode' => 'sum',
         'boost_mode' => 'replace'
        )
  );
$params['body']['query'] = $query;

```

$query\_string is set to bool, with match and should queries.  
The ES cluster does have all indexed scripts enabled.  
I'm using v. 1.7.5, php v. 5.6

---

<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:** [July 5, 2017, 10:41pm UTC](https://discuss.elastic.co/t/php-client-run-indexed-script-on-query/53565/2 "2017-07-05T22:41:39Z")

</div>


