gpt4 book ai didi

php - Multy如何获取Elasticsearch php的样本?

转载 作者:行者123 更新时间:2023-12-02 22:24:32 25 4
gpt4 key购买 nike

在 php 中利用 Elasticsearch 客户端。我如何在 ES 中找到很多文档,对于 id,在 SQL 中等于“WHERE id IN (1,2,3,4,9)”?对于单声道,我这样做

$ params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id'
  ];

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

如何获取一些记录?试过了,还是不行

$ params = [[
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id'
  ]
  [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id2'
  ]];

  $ response = $ client-> mget ($ params);

等等

$ params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => array ('my_id', 'my_id2')
  ];

  $ response = $ client-> mget ($ params);

API 是 PHP 只有 https: https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_getting_documents.html

就是这样,只有CURL请求https:https://www.elastic.co/guide/en/elasticsearch/reference/1.4/docs-multi-get.html

谁用过 ES,请帮忙!)

最佳答案

您只需要使用 ids过滤器,像这样:

$params = [
'index' => 'my_index',
'type' => 'my_type',
'body' => [
'query' => [
'filtered' => [
'filter' => [
'ids' => [
'values' => ['my_id', 'my_id2']
]
]
]
]
]
];


$results = $client->search($params);

更新

如果你绝对想使用mget,那么你应该这样做:

$ params = [
'index' => 'my_index',
'type' => 'my_type',
'body' => ['ids' => ['my_id', 'my_id2']]
];

$ response = $ client-> mget ($ params);

关于php - Multy如何获取Elasticsearch php的样本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32876543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com