gpt4 book ai didi

php - 用于文本数据类型的Elasticsearch index_options = docs不返回任何搜索结果

转载 作者:行者123 更新时间:2023-12-03 01:17:44 24 4
gpt4 key购买 nike

我一直在使用Elasticsearch 7.6和PHP客户端API进行所有操作。
我已经创建了Elasticsearch索引设置和映射,如下所示

$params = [
'index' => 'elasticindex',
'body' => [
'settings' => [
"number_of_shards" => 1,
"number_of_replicas" => 0,
"index.queries.cache.enabled" => false,
"index.soft_deletes.enabled" => false,
"index.requests.cache.enable" => false,
"index.refresh_interval" => -1
],
'mappings' => [
'_source' => [
"enabled" => false
],
'properties' => [
"text" => [
"type" => "text",
"index_options" => "docs"
]
]
]
]
];

我可以使用以下代码对文档进行索引
$params = array();
$params['index'] = 'elasticindex';
for($i = 1; $i <=2; $i++) {
$params['id'] = $i;
$params['body']['text'] = 'apple';
$responses = $client->index($params);
}

但是当我使用以下搜索查询时
  $params = [
'index' => 'elasticindex',
'body' => [
'query' => [
'match' => [
"text" => "apple"
]
]
]
];

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

我得到空结果如下
Array                                                                                                                                                   
(
[took] => 3
[timed_out] =>
[_shards] => Array
(
[total] => 1
[successful] => 1
[skipped] => 0
[failed] => 0
)

[hits] => Array
(
[total] => Array
(
[value] => 0
[relation] => eq
)

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

)

)

如果不尝试创建索引,则无需创建静态索引模板,elasticsearch动态映射可以很好地工作,并且可以获得结果。

目的是我希望elasticsearch仅在其反向索引中索引文档ID,而不是位置或偏移量,并且我只想检索匹配的文档ID作为结果。非常感谢帮助。提前致谢!

最佳答案

由于文档是由get处理程序而不是查询处理程序返回的,因此在对文档建立索引后,索引无法正确刷新。

如您所言,在您的配置中设置:

"index.refresh_interval" => -1

..表示该索引不会自动刷新。除了在非常高的吞吐量情况下或需要特定行为的情况下,几乎不需要更改刷新间隔。

关于php - 用于文本数据类型的Elasticsearch index_options = docs不返回任何搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61707808/

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