Elastic search scoring is always 0

1.3k views Asked by At

Any idea why ElasticSearch would always return a _score of 0 for all the search queries i do ?

Using Elastica, i am doing something like:

$elasticaClient= $this->getElasticaClient();
$elasticaIndex  = $elasticaClient->getIndex($this->getIndexName());   
$elasticaQuery  = new Elastica\Query\BoolQuery(); 

$queryAnd = new \Elastica\Query\BoolQuery();
$queryOr = new \Elastica\Query\BoolQuery();

$queryOr->addShould(new \Elastica\Query\Wildcard('search_field1', $keyword));
$queryOr->addShould(new \Elastica\Query\Wildcard('search_field2', $keyword));

$queryAnd->addMust($queryOr);
$elasticaQuery->addFilter($queryAnd);

$mainQuery = new \Elastica\Query();
$mainQuery->setQuery($elasticaQuery);

$elasticaResultSet = $elasticaIndex->search($mainQuery);

I get a bunch of results back, but always the _score for those results is 0, even if i enter the full word that can be found in the stored field(for a full match).

The mapping for the field is pretty simple:

'search_field1' => array(
    'type'              => 'string',
    'include_in_all'    => true,
    'analyzer'          => 'stringLowercase',
),

The stringLowercase analyzer is just:

'stringLowercase' => array(
    'type'      => 'custom',
    'tokenizer' => 'keyword',
    'filter'    => 'lowercase'
),

Moreover, even if i try to boost either of the fields, it does not seem to have any effect.

Can anybody shed some light over this?

1

There are 1 answers

0
T.Todua On

have you tried to query something nested like this?:

//i.e.
$queryField = new \Elastica\Query\QueryString($query);
$queryField->setDefaultOperator('OR');
$queryBool->addMustNot($queryField);
//then 
$queryOr = new \Elastica\Query\Wildcard('search_field1', $keyword);
$queryOr->addShould($queryBool);