best-fields策略,主要是说将某一个field匹配尽可能多的关键词的doc优先返回回来 most-fields策略,主要是说尽可能返回更多field匹配到某个关键词的doc,优先返回回来 POST /forum/_mapping/article { “properties”: { “sub_title”: { “type”: “string”, “analyzer”: “english”, “fields”: { “std”: { “type”: “string”, “analyzer”: “standard” } } } } }
POST /forum/article/_bulk { “update”: { “_id”: “1”} } { “doc” : {“sub_title” : “learning more courses”} } { “update”: { “_id”: “2”} } { “doc” : {“sub_title” : “learned a lot of course”} } { “update”: { “_id”: “3”} } { “doc” : {“sub_title” : “we have a lot of fun”} } { “update”: { “_id”: “4”} } { “doc” : {“sub_title” : “both of them are good”} } { “update”: { “_id”: “5”} } { “doc” : {“sub_title” : “haha, hello world”} }
GET /forum/article/_search { “query”: { “match”: { “sub_title”: “learning courses” } } }
{ “took”: 3, “timed_out”: false, “_shards”: { “total”: 5, “successful”: 5, “failed”: 0 }, “hits”: { “total”: 2, “max_score”: 1.219939, “hits”: [ { “_index”: “forum”, “_type”: “article”, “_id”: “2”, “_score”: 1.219939, “_source”: { “articleID”: “KDKE-B-9947-#kL5”, “userID”: 1, “hidden”: false, “postDate”: “2017-01-02”, “tag”: [ “java” ], “tag_cnt”: 1, “view_cnt”: 50, “title”: “this is java blog”, “content”: “i think java is the best programming language”, “sub_title”: “learned a lot of course” } }, { “_index”: “forum”, “_type”: “article”, “_id”: “1”, “_score”: 0.5063205, “_source”: { “articleID”: “XHDK-A-1293-#fJ3”, “userID”: 1, “hidden”: false, “postDate”: “2017-01-01”, “tag”: [ “java”, “hadoop” ], “tag_cnt”: 2, “view_cnt”: 30, “title”: “this is java and elasticsearch blog”, “content”: “i like to write best elasticsearch article”, “sub_title”: “learning more courses” } } ] } } sub_title用的是enligsh analyzer,还原了单词
https://www.elastic.co/guide/en/elasticsearch/reference/7.0/release-notes-7.0.0.html#breaking-7.0.0