16、使用原生cross-fiedls技术解决搜索弊端
可以解决 "operator": "and"
GET /forum/_search { "query":{ "multi_match": { "query": "Peter Smith", "type":"cross_fields", "operator": "and", "fields": ["author_first_name","author_last_name"] } } }
结果
{ "took" : 18, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 2.4079456, "hits" : [ { "_index" : "forum", "_type" : "_doc", "_id" : "1", "_score" : 2.4079456, "_source" : { "articleID" : "XHDK-A-1293-#fJ3", "userID" : 1, "hidden" : false, "postDate" : "2017-01-01", "sub_title" : "learning more courses", "author_first_name" : "Peter", "author_last_name" : "Smith", "new_author_last_name" : "Smith", "new_author_first_name" : "Peter", "follower_num" : 5, "view_cn" : 30, "title" : "this is java and elasticsearch blog", "content" : "i like to write best elasticsearch article" } } ] } }
问题1:只是找到尽可能多的field匹配的doc,而不是某个field完全匹配的doc
答: 解决,要求每个term都必须在任何一个field中出现
Peter,Smith
要求Peter必须在author_first_name或author_last_name中出现
要求Smith必须在author_first_name或author_last_name中出现
Peter Smith可能是横跨在多个field中的,所以必须要求每个term都在某个field中出现,组合起来才能组成我们想要的标识,完整的人名
原来most_fields,可能像Smith Williams也可能会出现,因为most_fields要求只是任何一个field匹配了就可以,匹配的field越多,分数越高
问题2:most_fields,没办法用minimum_should_match去掉长尾数据,就是匹配的特别少的结果 --> 解决,既然每个term都要求出现,长尾肯定被去除掉了
答:java hadoop spark --> 这3个term都必须在任何一个field出现了
比如有的document,只有一个field中包含一个java,那就被干掉了,作为长尾就没了
立志如山 静心求实
浙公网安备 33010602011771号