Question

Using Elastica - Elasticsearch PHP Client. There are so many fields but I want to search in "Screen_name" field. 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();
Was it helpful?

Solution

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".

Try using a Match query or a Query_String.

"Term" has special meaning in 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top