0

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 Answer 1

1

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'))
        )
    ):
Sign up to request clarification or add additional context in comments.

10 Comments

hi val, thanks for your answer :), but i do that er error --- Syntax error 500 Internal Server Error - JsonDeserializationError
Weird, can you make sure your arrays are properly nested and you can update your question with properly formatted code, please, will be easier to read (and debug). Thx
i have update my question, can u kindly have a look :)
Actually, I've updated my answer to better reflect what you want to do. Please try again.
thanks a lot for your answer, but somehow i am always getting that error, i have update my question again to explain it little more clear ...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.