简体   繁体   English

PHP Elasticsearch从索引中的所有文档中获取字段的值

[英]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. 我有一个带有索引的Elasticsearch,其中所有文档都具有相同的字段。 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. 我想创建一个运行查询的PHP脚本,该查询从该索引中的所有文档中获取该字段的值。

How could I go about doing this? 我该怎么做呢? I'm using Elasticsearch 6.3 and PHP 7.2. 我正在使用Elasticsearch 6.3和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' . @Ole您是否尝试仅查询字段'Company'?如果是,只需使用'_source'而不是'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 参考: https : //www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-request-source-filtering.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 php 中的索引 elasticsearch 获取所有数据 - Get all data from index elasticsearch in php elasticsearch使用PHP API获取索引中的文档总数 - elasticsearch get documents total count in index using php API 用PHP将大量文档索引为elasticsearch索引 - Indexing tons of documents to elasticsearch index with php 如何使用php mongo adapter从所有文档中取消设置字段? - How to unset a field from all documents with php mongo adapter? (Elasticsearch)如何获取所有文档的嵌套字段的最后一个元素然后执行子聚合 - (Elasticsearch) How to get the last element of a nested field of all documents then perform sub-aggregations 使用PHP客户端库从Elasticsearch中的别名获取索引名称 - Get index name from alias in elasticsearch using php client library 如果字段值非常大,则$ _GET的PHP数组缺少索引 - PHP Array from $_GET missing Index if field value is very large string 获取ElasticSearch中日期直方图上缺少字段的文档计数? - Get count of documents missing a field over a date histogram in ElasticSearch? Elasticsearch 2.3通过使用PHP库进行查询来删除类型中的所有文档 - Elasticsearch 2.3 Delete all documents in a type by query using PHP LIbrary Elasticsearch-PHP 7 返回给定映射的所有文档 - Elasticsearch-PHP 7 Return All documents of a given mapping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM