Php 使用elastica按给出空结果的术语进行搜索
使用Elastica-ElasticSearchPHP客户端。有很多字段,但我想在“屏幕名称”字段中搜索。我必须为此做些什么。我用了这个词,但没有成功。结果是空数组Php 使用elastica按给出空结果的术语进行搜索,php,search,elasticsearch,elastica,Php,Search,elasticsearch,Elastica,使用Elastica-ElasticSearchPHP客户端。有很多字段,但我想在“屏幕名称”字段中搜索。我必须为此做些什么。我用了这个词,但没有成功。结果是空数组 这是代码 // Load index (database) $elasticaIndex = $elasticaClient->getIndex('twitter_json'); //Load type (table) $elasticaType = $elasticaIndex->getType('tweet_jso
这是代码
// 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();
在不知道映射的情况下很难说,但文档属性“screen_name”很可能不包含术语“sohail” 尝试使用匹配查询或查询字符串
“术语”在弹性搜索中有特殊含义。术语是索引的基本原子单位。术语是在文本通过分析器运行后生成的。如果“screen_name”有一个与索引关联的分析器,“sohail”在保存到索引中之前正在以某种容量进行修改。谢谢您的回复。我添加了一组数据,elasticsearch自动将其映射。我只想在screen_name字段中搜索。使用term或任何其他方法。如果未指定分析器,ES将自动使用。尝试使用匹配查询,这可能对您有效。现在我尝试使用此查询,但再次返回空结果<代码>$elasticaQueryMatch=新Elastica\Query\Match()$elasticaQueryMatch->setField('screen_name','sohail')//在索引上搜索$elasticaResultSet=$elasticaIndex->search($elasticaQueryMatch);var_dump($elasticaResultSet);退出对不起,我不熟悉Elastica。尝试使用命令行中的原始CURL命令来确保您的查询工作正常(或者使用Insquisitor或Head之类的插件),然后将其转换为Elastica。感谢它现在工作正常。事实上,我不知道为什么屏幕名称不可搜索。但当我在文本字段中搜索时,它是有效的