2013-10-23 42 views
0

此查询很好用,但返回的结果太多。我想添加boost函数,但我不知道正确的语法。ElasticSearch如何使用增强

$data_string = '{ 
"from" : 0, "size" : 100, 
"sort" : [ 
    { "date" : {"order" : "desc"} } 
], 
"query": { 
     "more_like_this_field" : { 
      "thread.title" : { 
       "like_text" : "this is a test", 
       "min_word_len" : 4, 
       "min_term_freq" : 1, 
       "min_doc_freq" : 1 
      } 
     } 
    } 
}'; 

回答

0

按照docs,你只需将它添加到其他参数:

... 
"thread.title" : { 
    "like_text" : "this is a test", 
    "min_word_len" : 4, 
    "min_term_freq" : 1, 
    "min_doc_freq" : 1, 
    "boost": 1.0 
} 
... 

此外,如果你有太多的文档,你可以尝试增加min_term_freqmin_doc_freq,太。

+0

谢谢你的回复,miku。我已经尝试过,但增加了“提升”:1.0这样做似乎什么都不做。我试着将号码改为更高的号码,但不会改变结果。 –

1

找到解决方案。看起来像使用fuzzy_like_this_field和min_similarity是要走的路。

$data_string = '{ 
"from" : 0, "size" : 100, 
"query": { 
     "fuzzy_like_this_field" : { 
      "thread.title" : { 
       "like_text" : "this is a test", 
       "min_similarity": 0.9 
      } 
     } 
    } 
}';