phpelasticsearch

ElasticSearch without response data in PHP


This is my mapping:

$ curl -X GET -k -u elastic:elastic "http://127.0.0.1:9200/_mapping"

{"photobank":{"mappings":{"properties":{"id":{"type":"long"},"title":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}}

I inserted test data like title: "aaa" and "bbb" and "ccc" like this:

array (
  'index' => 'photobank',
  'id' => '79',
  'body' => 
  array (
    'title' => 'aaa',
    'id' => 79,
  ),
)
$response = $client->index($params);

Data are saved with response statusCode=201 and reasonPhrase="Created". But when I search inserted data I have no data response from ES:

$params = [
    'index' => 'photobank',
    'body'  => [
        'query' => [
            /*'match' => [
                'title' => 'aaa'
            ],*/
            'bool' => [
                'must' => [
                    'match' => [
                        'title' => 'aaa'
                    ]
                ],
            ]
        ]
    ],
];
$response = $client->search($params);

$response has statusCode 200 only but nothing more. Where are result data or is my query wrong?


Solution

  • After more search answer I found how to get data. Its over call another functions like this:

    $body = (string)$response->getBody();
    $bodyArray = json_decode($body, true);