简体   繁体   English

如何通过elastica在弹性搜索中的字符串中找到字符串?

[英]how to find a string within a string in elastic search via elastica?

let's say I want to have a search result whereby this particular field of each item has the string eg # hashtag 假设我想要一个搜索结果,其中每个项目的此特定字段都具有字符串,例如#hashtag

like for example i have a data field named description, so what I want to get from the result, only those items that has a string 'hashtag' within their description like eg 例如,例如,我有一个名为description的数据字段,因此我想从结果中获取的信息仅是描述中具有字符串“ hashtag”的那些项,例如

"the english alphabet has 28 letters #hashtag"

so, that item with this description field above should be included in the search result, because the description field value string has a "#hashtag" string inside. 因此,具有上述描述字段的项目应包含在搜索结果中,因为描述字段值字符串的内部带有“ #hashtag”字符串。

how to do that in elastica ? 如何在Elastica中做到这一点? what filtering or function should I use? 我应该使用什么过滤或功能?

<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// The !== operator can also be used.  Using != would not work as expected
// because the position of 'a' is 0. The statement (0 != false) evaluates 
// to false.
if ($pos !== false) {
     echo "The string '$findme' was found in the string '$mystring'";
         echo " and exists at position $pos";
} else {
     echo "The string '$findme' was not found in the string '$mystring'";
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM