专注于大数据及容器云核心技术解密,可提供全栈的大数据+云原生平台咨询方案,请持续关注本套博客。如有任何学术交流,可随时联系。更多内容请关注《数据云技术社区》公众号。
POST /forum/article/_bulk { "update": { "_id": "1"} } { "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} } { "update": { "_id": "2"} } { "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} } { "update": { "_id": "3"} } { "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} } { "update": { "_id": "4"} } { "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} } { "update": { "_id": "5"} } { "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} } //实现cross-fields搜索 PUT /forum/_mapping/article { "properties": { "new_author_first_name": { "type": "string", "copy_to": "new_author_full_name" }, "new_author_last_name": { "type": "string", "copy_to": "new_author_full_name" }, "new_author_full_name": { "type": "string" } } } //其实效果不佳 POST /forum/article/_bulk { "update": { "_id": "1"} } { "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} } --> Peter Smith { "update": { "_id": "2"} } { "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} } --> Smith Williams { "update": { "_id": "3"} } { "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} } --> Jack Ma { "update": { "_id": "4"} } { "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} } --> Robbin Li { "update": { "_id": "5"} } { "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} } --> Tonny Peter Smith GET /forum/article/_search { "query": { "match": { "new_author_full_name": "Peter Smith" } } } //测试短语匹配 POST /forum/article/5/_update { "doc": { "content": "spark is best big data solution based on scala ,an programming language similar to java spark" } } //单单包含java的doc也返回了,不是我们想要的结果 GET /forum/article/_search { "query": { "match": { "content": "java spark" } } } 复制代码
GET /forum/article/_search { "query": { "match_phrase": { "content": "java spark" } } } 复制代码
hello world, java spark doc1 hi, spark java doc2 hello doc1(0) wolrd doc1(1) java doc1(2) doc2(2) spark doc1(3) doc2(1) 了解什么是分词后的position GET _analyze { "text": "hello world, java spark", "analyzer": "standard" } 复制代码
GET /forum/article/_search { "query": { "match_phrase": { "content": { "query": "spark data", "slop": 3 } } } } spark is best big data solution based on scala ,an programming language similar to java spark spark data --> data --> data spark --> data GET /forum/article/_search { "query": { "match_phrase": { "content": { "query": "java best", "slop": 15 } } } } { "took": 3, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 2, "max_score": 0.65380025, "hits": [ { "_index": "forum", "_type": "article", "_id": "2", "_score": 0.65380025, "_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", "author_first_name": "Smith", "author_last_name": "Williams", "new_author_last_name": "Williams", "new_author_first_name": "Smith" } }, { "_index": "forum", "_type": "article", "_id": "5", "_score": 0.07111243, "_source": { "articleID": "DHJK-B-1395-#Ky5", "userID": 3, "hidden": false, "postDate": "2017-03-01", "tag": [ "elasticsearch" ], "tag_cnt": 1, "view_cnt": 10, "title": "this is spark blog", "content": "spark is best big data solution based on scala ,an programming language similar to java spark", "sub_title": "haha, hello world", "author_first_name": "Tonny", "author_last_name": "Peter Smith", "new_author_last_name": "Peter Smith", "new_author_first_name": "Tonny" } } ] } } 复制代码
GET /forum/article/_search { "query": { "bool": { "must": [ { "match": { "content": "java spark" } } ], "should": [ { "match_phrase": { "content": { "query": "java spark", "slop": 50 } } } ] } } } { "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 2, "max_score": 1.258609, "hits": [ { "_index": "forum", "_type": "article", "_id": "5", "_score": 1.258609, "_source": { "articleID": "DHJK-B-1395-#Ky5", "userID": 3, "hidden": false, "postDate": "2017-03-01", "tag": [ "elasticsearch" ], "tag_cnt": 1, "view_cnt": 10, "title": "this is spark blog", "content": "spark is best big data solution based on scala ,an programming language similar to java spark", "sub_title": "haha, hello world", "author_first_name": "Tonny", "author_last_name": "Peter Smith", "new_author_last_name": "Peter Smith", "new_author_first_name": "Tonny", "followers": [ "Jack", "Robbin Li" ] } }, { "_index": "forum", "_type": "article", "_id": "2", "_score": 0.68640786, "_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", "author_first_name": "Smith", "author_last_name": "Williams", "new_author_last_name": "Williams", "new_author_first_name": "Smith", "followers": [ "Tom", "Jack" ] } } ] } } 复制代码
执笔小记,温故知新
专注于大数据及容器云核心技术解密,可提供全栈的大数据+云原生平台咨询方案,请持续关注本套博客。如有任何学术交流,可随时联系。更多内容请关注《数据云技术社区》公众号。