我一直在使用 Elasticsearch 7.6 和 PHP 客户端 API 进行所有操作。我创建了弹性搜索索引设置和映射如下
$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 动态映射效果很好,并且我得到了结果。
目标是我希望弹性搜索仅在其倒排索引中索引文档 ID,而不是位置或偏移量,并且我只想检索匹配的文档 ID 作为结果。非常感谢您的帮助。提前致谢!