14、基于multi_match 使用cross-fields search
造数据
POST /forum/_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/_search { "query": { "multi_match": { "query": "Peter Smith", "type": "cross_fields", "fields": [ "author_first_name", "author_last_name" ] } } }
等价于
GET /forum/_search { "query": { "multi_match": { "query": "Peter Smith", "type": "best_fields", "fields": [ "author_first_name", "author_last_name" ] } } }
返回结果
{ "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : 1.2039728, "hits" : [ { "_index" : "forum", "_type" : "_doc", "_id" : "1", "_score" : 1.2039728, "_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" } }, { "_index" : "forum", "_type" : "_doc", "_id" : "2", "_score" : 1.2039728, "_source" : { "articleID" : "KDKE-B-9947-#kL5", "userID" : 1, "hidden" : false, "postDate" : "2017-01-02", "sub_title" : "learned a lot of course", "author_first_name" : "Smith", "author_last_name" : "Williams" } } ] } }
立志如山 静心求实
浙公网安备 33010602011771号