ruby - ElasticSearch - if field is null, treat as 0? -


i using elasticsearch, , running nullpointerexceptions because field basing score on null several documents.

how make elasticsearch treat these null fields 0?

fwiw, i'm using tire gem , ruby code:

s = tire.search "articles"             query                 custom_score :script => "_score < 2 ? 0 : doc['num_likes'].value"                    match fields, keyword                 end                  end                end 

i discovered need this:

_score < 2 ? 0 : (doc['num_likes'].empty ? 0 : doc['num_likes'].value) 

Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -