本文共 4096 字,大约阅读时间需要 13 分钟。
POST /forum/article/_bulk{ "update": { "_id": "1"} }{ "doc" : { "title" : "this is java and elasticsearch blog"} }{ "update": { "_id": "2"} }{ "doc" : { "title" : "this is java blog"} }{ "update": { "_id": "3"} }{ "doc" : { "title" : "this is elasticsearch blog"} }{ "update": { "_id": "4"} }{ "doc" : { "title" : "this is java, elasticsearch, hadoop blog"} }{ "update": { "_id": "5"} }{ "doc" : { "title" : "this is spark blog"} }
GET /forum/article/_search { "query": { "match": { "title": "java elasticsearch" } } }
GET /forum/article/_search{ "query": { "match": { "title": { "query": "java elasticsearch", "operator": "and" } } }}
GET /forum/article/_search{ "query": { "match": { "title": { "query": "java elasticsearch spark hadoop", "minimum_should_match": "75%" } } }}
GET /forum/article/_search{ "query": { "bool": { "must": { "match": { "title": "java" }}, "must_not": { "match": { "title": "spark" }}, "should": [ { "match": { "title": "hadoop" }}, { "match": { "title": "elasticsearch" }} ] } }}
must和should搜索对应的分数,加起来,除以must和should的总数
should是可以影响相关度分数的
搜索的结果:
{ "took": 6, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 3, "max_score": 1.3375794, "hits": [ { "_index": "forum", "_type": "article", "_id": "4", "_score": 1.3375794, "_source": { "articleID": "QQPX-R-3956-#aD8", "userID": 2, "hidden": true, "postDate": "2017-01-02", "tag": [ "java", "elasticsearch" ], "tag_cnt": 2, "view_cnt": 80, "title": "this is java, elasticsearch, hadoop blog" } }, { "_index": "forum", "_type": "article", "_id": "1", "_score": 0.53484553, "_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" } }, { "_index": "forum", "_type": "article", "_id": "2", "_score": 0.19856805, "_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" } } ] }}
GET /forum/article/_search{ "query": { "bool": { "should": [ { "match": { "title": "java" }}, { "match": { "title": "elasticsearch" }}, { "match": { "title": "hadoop" }}, { "match": { "title": "spark" }} ], "minimum_should_match": 3 } }}
转载地址:http://keonn.baihongyu.com/