duanjunjie0196 2016-02-12 06:18
浏览 355
已采纳

如何使用ElasticSearch索引搜索单词的一部分

I've recently started using ElasticSearch and I can't seem to make it search for a part of a word.

Example: I have three documents from my couchdb indexed in ElasticSearch:

{
 "_id" : "1",
 "name" : "John Doeman",
 "function" : "Janitor"
}
{
 "_id" : "2",
 "name" : "Jane Doewoman",
 "function" : "Teacher"
}
{
 "_id" : "3",
 "name" : "Jimmy Jackal",
 "function" : "Student"
} 

So now, I want to search for all documents containing "Doe"

curl http://localhost:9200/my_idx/my_type/_search?q=Doe

That doesn't return any hits. But if I search for

curl http://localhost:9200/my_idx/my_type/_search?q=Doeman

It does return one document (John Doeman).

Am trying with this url 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);

How can I make ElasticSearch find both John Doeman and Jane Doewoman when I search for "Doe" ?

  • 写回答

2条回答 默认 最新

  • douaonong7807 2016-02-12 06:22
    关注

    You can simply try using a wildcard first:

    curl http://localhost:9200/my_idx/my_type/_search?q=Doe*
    

    If that's enough, you can get away with that. Otherwise, there are other more advanced solutions by creating custom analyzers with edge ngram tokenizers and filters.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器