2015-04-06 104 views
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*';

搜索返回結果爲零秒。

是否有一些配置需要設置爲允許部分字符串搜索?

+1

你需要看看ngrams。我不知道如何使用PHP進行設置,但是這裏有一篇關於ngrams的博客文章(劇透:請看最後一部分開始):http://blog.qbox.io/an-introduction- to-ngrams-in-elasticsearch –

+0

優秀閱讀!謝謝! ngrams絕對是我所追求的。 – johncorser

回答

1

我解決了這個問題,同時通過一個單獨的stackoverflow問題,我問here。工作腳本在那裏。

感謝@ sloan-ahrens給我這個方向

相關問題