Hey there.  It's possible, but it requires explicit object creation via the 
PHP \stdClass() object.  PHP isn't very good at deciding between arrays and 
objects when using json_encode, unless you use explicit objects.

Untested, but try this:

$scriptScore = new \stdClass();$scriptScore->script = "doc['boostfield'].value";
$qry = array(
    'query' => array(
        'function_score' => array(
            'functions' => array(
                array("script_score" => $scriptScore)
            ),
            'query' => array(
               'query_string' => array('query' => 'MyQuery')
            ),
            'score_mode' => 'multiply'
        )
    ));
$searchParams['body'] = $qry;
$client = new Elasticsearch\Client();$retDoc = 
$client->search($searchParams);print_r($retDoc);


This particular PHP irritation just came up the other day as a ticket 
(https://github.com/elasticsearch/elasticsearch-php/issues/47), so you're 
not alone in being confused.  I'm going to write some documentation about 
how to accomplish it, since the syntax is different from normal DSL queries.

-Zach


On Wednesday, March 12, 2014 2:47:00 PM UTC-4, Erdal Gunyar wrote:
>
> Hi everybody,
>
> Does anyone here successfully implemented function_score with 
> elasticsearch-php?
> Of course, without passing all the body as a JSON string.
>
> I've actually tried but it failed, it looks like it's impossible to pass 
> the "array+object" located in the "functions" part :
>     "query": {
>         "function_score": {
>             "query": {  
>                 "query_string": {
>                 "query": "MyQuery",
>                 }
>             },
>             "functions": [{
>                 "script_score": { 
>                     "script": "doc['boostfield'].value"
>                 }
>             }],
>             "score_mode": "multiply"
>         }
>     },
>
> Any help will be appreciated! :)
>
> Thanks,
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/479748b5-55b4-4c2d-a370-4d8740118b5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to