0
votes

i want to query based on the sources, so i put the codition in my base query that it should query always based on the source, where the source value is stored in the variable $webAddress.

and if nothing is selected it should run the default query but it always returning me an weird error !

error message ---

enter image description here

so why i am getting this error, anyone knows how to solve this weird problem !

Thanks a lot in advanced.

enter image description here

  1. at AbstractJsonSerializer ::jsonDecode ('{"took":291,"timed_out":false,"_shards":{"total":2,"successful":2,"failed":0},"hits":{"total":10,"max_score":0.94276774,"hits":[{"_index":"myIndex","_type":"myType","_id":"p717ff3c9460bf8a52407d6e4a63f239dbeb052cf","_score":0.94276774,"_source":{ "content": "A beautiful backyard has become a suburban status symbol much like a brand-new car in the driveway. Upgrading your outdoor space is not only uplifti ......} in vendor/elasticsearch/elasticsearch/src/Elasticsearch/Serializers/SmartSerializer.php at line 39 +

  2. at SmartSerializer ->deserialize ('{"took":291,"timed_out":false,"_shards":{"total":2,"successful":2,"failed":0},"hits":{"total":10,"max_score":0.94276774,"hits":[{"_index":"myIndex","_type":"myType","_id":"p717ff3c9460bf8a52407d6e4a63f239dbeb052cf","_score":0.94276774,"_source":{ "content": "A beau ....}

    4.at Transport ->performRequest ('GET', '/myType/content/_search', array('size' => '30'), array('query' => array('bool' => array('must' => array(array('query_string' => array('default_field' => 'source', 'query' => 'aa.com', 'bb.com', 'cc.com'))))), 'sort' => array())) in vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/AbstractEndpoint.php at line 86 +

  3. at AbstractEndpoint ->performRequest () in vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php at line 1012 +

if i print the query which is executing i get ---

{
    "index": "myIndex",
    "type": "myType",
    "size": 30,
    "body": {
        "query": {
            "bool": {
                "must": [
                    {
                        "query_string": {
                            "default_field": "source",
                            "query": "aa.com, bb.com, cc.com"
                        }
                    }
                ]
            }
        },
        "sort": []
    } }
1

1 Answers

1
votes

In your PHP code you have inserted twice the query/bool/must combo. Simply remove the first one and you should be fine.

    $params = array(
        'index' => "myIndex",
        'type' => "myType",
        'xize' => 100,
        'body' => array(
            'query' => array(
                'bool' => array(
                    'must' => array(

                    )
                )
            ),
            'sort' => array()
        )
    );

    $params['body']['query']['bool']['must'][] = array(
        'query_string' => array(
            'default_field' => 'source',
            'query' => implode(', ', array_column($webAddress, 'source'))
        )
    ):