gpt4 book ai didi

php - 在 Elasticsearch 中如何使用像算子?

转载 作者:行者123 更新时间:2023-12-03 01:56:55 26 4
gpt4 key购买 nike

如何在Elasticsearch中搜索数据。我的意思是,如果我在文本字段中输入了比该单词相关数据更多的数据,则应搜索并显示。
我试过的

$name = $this->getRequest()->getPost('name'); 

if(isset($name) && !empty($name)) /*checking condition */
{
$searchParams['body']['query']['bool']['must'][]['term'] ['couchbaseDocument.doc.name']= '*$name*'; /* elasticsearch query for filter the partial name
}

最佳答案

    public function ajaxhandlerAction() {

$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);

switch ($method) {
case "searchgroups":
if ($this->getRequest()->isPost()) {
$name = $this->getRequest()->getPost('name');
$client = new Elasticsearch\Client();
$searchParams = array();
$searchParams['index'] = 'data';
$searchParams['type'] = 'couchbaseDocument';
$searchParams['from'] = 0;
$searchParams['size'] = 20;

if (isset($name) && !empty($name)) {
$searchParams['body']['query']['filtered']['query']['multi_match']['query'] = $name;
$searchParams['body']['query']['filtered']['query']['multi_match']['type'] = "phrase_prefix";
$searchParams['body']['query']['filtered']['query']['multi_match']['fields'] = ['name', 'city', 'state', 'country'];
$groupResults = $client->search($searchParams);
}
}
break;
default:
break;
}
}

关于php - 在 Elasticsearch 中如何使用像算子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35916764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com