Reputation: 1667
Searching "follow back" in Twitter User's description field that I have indexed already with following mapping.
Note: Only Highlight some of mapping.
1.
'analysis' => array(
'analyzer' => array(
'myanalyzer' => array(
"type" => "standard",
'stopwords' => '_none_',
),
)
)
2.
$mapping->setParam('index_analyzer', 'myanalyzer');
$mapping->setParam('search_analyzer', 'myanalyzer');
3.
'description' => array('type' => 'string', "index" => "not_analyzed"),
4.
//search something
$queryString = new \Elastica\Query\QueryString();
$queryString->setDefaultOperator( "AND" );
// $queryString->setFields(array("user.description"));
$queryString->setQuery('follow back');
When Searched while setFields is commented it gives me lot of results like
IF YOU FOLLOW ILL FOLLOW BACK! :) 100% follow back! :)
Follow me i follow back :) instagram:juliemar25 i follow back
But after uncomment setFields and defaultOperator to AND, then it show no results. AND by uncomment setFields and defaultOperator to OR, it shows me only results that have "follow" in description nothing else.
Q1: Why white space not working on setFields instead working with _all?
While Using Match Query
$matchQuery = new \Elastica\Query\Match();
$matchfield = "user.description";
$queryToMatch = "follow back";
$matchQuery->setFieldQuery($matchfield, $queryToMatch);
It also show only two results that have "follow back" only in description. But after changing to match field to _all it show lot of results that contains "follow back" in description field
Q2. Why it is happening? How can I search for space separated words?
Upvotes: 1
Views: 971
Reputation: 17441
This is because you have set "description" field to be not_analyzed as per the mapping above.
This would result in the description field payload being indexed as is and a match occurs when the 'description' field is an exact search phrase which in this case is "follow back"
Removing "index" => "not_analyzed" should fix it.
Upvotes: 1