elasticsearch,Php,elasticsearch" /> elasticsearch,Php,elasticsearch" />

ElasticSearch PHP-获取类型/索引中10个(最近)项的列表

ElasticSearch PHP-获取类型/索引中10个(最近)项的列表,php,elasticsearch,Php,elasticsearch,我有一个名为publications\u items的索引和一个名为“publication”的类型 我想要最近增加的10种出版物。(一些匹配原则) 我正在使用ElasticSearch PHP() 基本上,我只是在做一个默认的get,但我不知道如何在ElasticSearchPHP中这样做 在sense.qbox.io中,我需要: POST /publications_items/_search { "query": { "match_all": {} } } 而且效

我有一个名为publications\u items的索引和一个名为“publication”的类型

我想要最近增加的10种出版物。(一些匹配原则)

我正在使用ElasticSearch PHP()

基本上,我只是在做一个默认的get,但我不知道如何在ElasticSearchPHP中这样做

在sense.qbox.io中,我需要:

POST /publications_items/_search {    "query": {
      "match_all": {}    } }
而且效果很好

映射:

PUT /publications_items/ {    "mappings": {
      "publication": {
         "properties": {
            "title": {
               "type": "string"
            },
            "url": {
               "type": "string"
            },
            "description": {
               "type": "string"
            },
            "year": {
               "type": "integer"
            },
            "author": {
               "type": "string"
            }
         }
      }    } }
你需要:

在搜索查询中,您需要并检索:

特别是在Elasticsearch PHP中:

  • 映射更改:
  • 查询:

幸运的是,有可能看到您的映射吗?对不起,我将讨论您的格式
PUT /test/doc/_mapping
{
  "_timestamp": {
    "enabled": "true",
    "store": "true"
  }
}
GET /test/_search
{
  "sort" : {
    "_timestamp" : { "order" : "desc" }
  },
  "from" : 0, "size" : 10
}
require 'vendor/autoload.php';

$client = new Elasticsearch\Client();
$params = array();

$params2 = [
         '_timestamp' => [
             'enabled' => 'true',
             'store' => 'true'
         ]
];
$params['index']='test';
$params['type']='doc';
$params['body']['doc']=$params2;
$client->indices()->putMapping($params);
require 'vendor/autoload.php';

$client = new Elasticsearch\Client();

$json = '{
  "sort" : {
    "_timestamp" : { "order" : "desc" }
  },
  "from" : 0, "size" : 10
}';

$params['index'] = 'test';
$params['type']  = 'doc';
$params['body'] = $json;

$results = $client->search($params);
echo json_encode($results, JSON_PRETTY_PRINT);