简体   繁体   中英

PHP Elasticsearch GET value of a field from all documents in index

I've an Elasticsearch with an index where all documents have the same fields. One of these fields is called "Company".

I want to create a PHP script that runs a query that gets the value of that field from all the documents in that index.

How could I go about doing this? I'm using Elasticsearch 6.3 and PHP 7.2.

This does not work but should help in understanding what I'm trying to do:

$params = [
    'index' => 'aksjeregisteret2017',
    'type' => '_doc',
    'field' => ['Company']
];

$response = $es->get($params);

@Ole Are you trying to query only the field 'Company'?If so just use '_source' instead of 'field' . So your

 $params = [
    'index' => 'aksjeregisteret2017',
    'type' => '_doc',

];
$params['body']['_source' ]= 'Company';
$params['body']['query']['match_all']['boost'] = 1.2;
$response = $es->search($params);

Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM