1
我想讓elasticsearch允許我使用php client library搜索部分字符串。如何使用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*';
搜索返回結果爲零秒。
是否有一些配置需要設置爲允許部分字符串搜索?
你需要看看ngrams。我不知道如何使用PHP進行設置,但是這裏有一篇關於ngrams的博客文章(劇透:請看最後一部分開始):http://blog.qbox.io/an-introduction- to-ngrams-in-elasticsearch –
優秀閱讀!謝謝! ngrams絕對是我所追求的。 – johncorser