【发布时间】:2019-07-22 23:41:10
【问题描述】:
ElasticSearch 对数据进行标记。 所以“这个-那个”被分成 2 个标记。 如果有区别,我使用的是 6.6 版本的 ES。 我有文档,它们具有不同的字段,例如标题、描述、名称等。 为了让我们有一个唯一的标识符,标题“这个那个”中的文本被翻译成“这个-那个”。 我正在尝试查询将返回该文档的“this-that”。 我已经尝试了各种各样的事情。我尝试了此论坛中其他问题的建议,以及https://www.elastic.co/guide/en/elasticsearch/reference/current/analyzer.html 页面中的说明。 不幸的是,似乎没有任何效果。 您的帮助将不胜感激。 提前谢谢你。
https://www.elastic.co/guide/en/elasticsearch/reference/current/analyzer.html
<?php
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$hosts = ['localhost:9200'];
$client = ClientBuilder::create()
->setHosts($hosts)
->build();
$params = array();
$params = [
'index' => 'shows',
'type' => '_doc',
'body' => [
'size'=> 10000,
'query' => [
'bool' => [
'must' => [ 'match' => [ 'name' => 'this-that'] ],
]
]
]
];
$response = $client->search($params);
print_r($response);
?>
没有错误,但它会找到名称字段中包含单词“this”和单词“that”的所有实例。 我只想取回一份文件!
【问题讨论】:
-
你能在
shows索引上发布你的配置吗? -
如果您使用默认映射,请将
name替换为name.keyword,否则更新映射以添加keyword字段或更改字段的分析器。 -
这个answer 可能会对你有所帮助。
-
$params = [ 'index' => 'shows', 'body' => [ 'settings' => [ 'number_of_shards' => 3, 'number_of_replicas' => 0, 'index. mapping.ignore_malformed' => true ],
-
'mappings' => [ '_doc' => [ 'date_detection' => false, 'properties' => [ 'pubdate' => [ 'type' => 'date', 'ignore_malformed ' => true ] , 'seasons' => [ 'properties' => [ 'episodes' => [ 'properties' => [ 'pubdate' => [ 'type' => 'date', 'ignore_malformed' =>真 ] ] ]
标签: php elasticsearch