Elasticsearch-PHP 7 Return All documents of a given mapping

1.9k Views Asked by At

Summary

Failing to get any/all documents from my ElasticSearch instance using the ElasticSearch-PHP 7 package.

When I run Curl query, works just fine. So I know I have bulk inserted the documents properly. Meaning that documents do exist.

Curl Success

Curl Call

curl -X GET -u elastic:changeme 'ltr-elasticsearch:9200/experiences_1621701804/region/_search?pretty'
{
    "took": 58,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 100,
        "max_score": 1,
        "hits": [
            {
                "_index": "experiences_1621701804",
                "_type": "region",
                "_id": "14",
                "_score": 1,
                "_source": {
                    "id": 14,
                    "name": "Dallas",
                    "active": "1",
                    "image": {
                        "domain": null,
                        "original": "https://d2l34t1fl9ccx8.cloudfront.net/media/image/d/a/dallas.jpg",
                        "small": "https://d2l34t1fl9ccx8.cloudfront.net/media/image/d/a/dallas.jpg",
                        "thumbnail": "https://d2l34t1fl9ccx8.cloudfront.net/media/image/d/a/dallas.jpg"
                    }
                }
            }
            // many more document results show up here
        ]
    }
};

Elasticsearch-PHP 7 Search Manual

https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/search_operations.html

// Build Params with Raw JSON
$params = [
    'index' => 'experiences_1621701804',
    'type' => 'region',
    'body'  => '{
        "query": {
            "match_all": {}
        }
    }',
];

// Also tried
$params = [
    'index' => 'experiences_1621701804',
    'type' => 'region',
    'body'   => [
        'query' => [
            'match_all' => new \stdClass()
        ]
    ]
];

// Trigger Search
$results = $esClientBuilder->search($params);
print_r($results);

Results Dumped Fails To Show Results

(
    [took] => 0
    [timed_out] =>
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [skipped] => 0
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 0
            [max_score] =>
            [hits] => Array
                (
                )

        )
)

Updated Possible Solution?

Rookie move, I should have compared versions. There is a version mapping for the package elasticsearch/elasticsearch.

https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/installation.html

I am currently on v 5.2 of elasticsearch/elasticsearch.

It looks like v5 does not support match_all? Which to me is really odd. I would think a fundamental feature would be to get ALL documents. I get it's a search tool, and maybe it just focused on filtered search results. And it's possible it just handles it in a different way undocumented.

v5: https://www.elastic.co/guide/en/elasticsearch/client/php-api/5.x/_match_query.html

I am currently locked out of my work VPN and unable to upgrade packages to test. Will follow up once I am able.

1

There are 1 best solutions below

0
On

remove body will return all document

 $params = [
        'index' => 'your_index',
    ];
    $response = $this->elasticsearch->search($params);
    dump($response);