如何允许使用elasticsearch php进行部分字符串搜索


How to allow partial string searches with elasticsearch php

我正在尝试使用elasticsearch来使用php客户端库搜索部分字符串。

我有一个类似的脚本

// create an index
$params = array();
$params['body']  = array('testField' => 'abc');
$params['index'] = 'my_index';
$params['type']  = 'my_type';
$params['id']    = 'my_id';
$ret = $client->index($params);
// search for that index
$searchParams['index'] = 'my_index';
$searchParams['type']  = 'my_type';
$searchParams['body']['query']['match']['testField'] = 'abc';
$queryResponse = $client->search($searchParams); // contains the indexed `abc` testField

这是有效的,我能够找到我刚刚创造的东西。

但是,当我更换时

$searchParams['body']['query']['match']['testField'] = 'abc';

带有

$searchParams['body']['query']['match']['testField'] = 'a';

$searchParams['body']['query']['match']['testField'] = 'a*';

搜索结果为零。

是否需要设置一些配置以允许部分字符串搜索?

我在解决这里提出的一个单独的stackoverflow问题时解决了这个问题。工作脚本就在那里。

感谢@sloan ahrens为我提供有关的指导