简体   繁体   English

使用弹性搜索按字词给出空结果

[英]Search by term giving empty result using elastica

Using Elastica - Elasticsearch PHP Client. 使用Elastica-Elasticsearch PHP客户端 There are so many fields but I want to search in "Screen_name" field. 字段太多,但是我想在“ Screen_name”字段中搜索。 What I have to do for it. 我要为此做些什么。 I used term but without success. 我用术语但没有成功。 Result is empty array 结果为空数组
Here is the code. 这是代码。

// Load index (database)
$elasticaIndex = $elasticaClient->getIndex('twitter_json');

//Load type (table)
$elasticaType = $elasticaIndex->getType('tweet_json');


$elasticaFilterScreenName   = new \Elastica\Filter\Term();    
$elasticaFilterScreenName->setTerm('screen_name', 'sohail'); 

//Search on the index.
$elasticaResultSet  = $elasticaIndex->search($elasticaFilterScreenName);

var_dump($elasticaResultSet); exit;
$elasticaResults    = $elasticaResultSet->getResults();
$totalResults       = $elasticaResultSet->getTotalHits();

It's hard to say without knowing your mapping, but there is a good chance the document property "screen_name" does not contain the term "sohail". 在不知道您的映射的情况下很难说,但是很有可能文档属性“ screen_name”不包含术语“ sohail”。

Try using a Match query or a Query_String. 尝试使用匹配查询或Query_String。

"Term" has special meaning in ElasticSearch. “条款”在ElasticSearch中具有特殊含义。 A Term is the base, atomic unit of an index. 术语是索引的基本原子单位。 Terms are generated after your text is run through an analyzer. 在您的文本通过分析仪运行后生成术语。 If "screen_name" has an analyzer associated with the index, "sohail" is being modified in some capacity before being saved into the index. 如果“ screen_name”具有与索引关联的分析器,则“ sohail”将被修改为某种容量,然后再保存到索引中。

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

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