我最近开始使用ElasticSearch,但似乎无法让它搜索单词的一部分。
示例:我有我的ouchdb中的三个文档,在ElasticSearch中建立了索引:
{
"_id" : "1",
"name" : "John Doeman",
"function" : "Janitor"
}
{
"_id" : "2",
"name" : "Jane Doewoman",
"function" : "Teacher"
}
{
"_id" : "3",
"name" : "Jimmy Jackal",
"function" : "Student"
}
所以现在,我要搜索包含“Doe”的所有文档
curl http://localhost:9200/my_idx/my_type/_search?q=Doe
那不会返回任何点击。但是如果我寻找
curl http://localhost:9200/my_idx/my_type/_search?q=Doeman
它确实返回一个文档(John Doeman)。
我正在尝试使用此网址
http://localhost/el/index.php?str=*doe*
。<?php
require 'vendor/autoload.php';
$client = Elasticsearch\ClientBuilder::create()->build();
$params = array();
$params['index'] = 's3';
$params['type'] = 's3files';
$params['body']['query']['match']['content'] = $_GET['str'];
$result = $client->search($params);
echo "<pre>";
print_r($result);
当我搜索“Doe”时,如何使ElasticSearch同时找到John Doeman和Jane Doewoman?
最佳答案
您可以简单地先尝试使用通配符:
curl http://localhost:9200/my_idx/my_type/_search?q=Doe*
如果足够,您就可以摆脱它。否则,通过使用边缘ngram tokenizers和filters创建自定义分析器,还有其他更高级的解决方案。
关于php - 如何使用ElasticSearch索引搜索单词的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35356062/