日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ElasticSearch关于映射mapping介绍

發(fā)布時間:2025/3/15 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ElasticSearch关于映射mapping介绍 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#首先我們還是先增加幾個文檔

PUT /myindex/article/1 {"post_date": "2020-03-14","title": "Java","content": "java is the best language","author_id": 119 }PUT /myindex/article/2 {"post_date": "2020-03-14" ,"title": "html","content": "I like html","author_id": 120 } PUT /myindex/article/3 {"post_date": "2020-03-14" ,"title": "es","content": "Es is distributed document store" ,"author_id": 110 }

?

#查看es的文檔映射mapping的數(shù)據(jù)結(jié)構(gòu) GET /myindex/article/_mapping

mapping數(shù)據(jù)結(jié)構(gòu)如下:?

{"myindex" : {"mappings" : {"article" : {"properties" : {"author_ id" : {"type" : "long"},"content" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"post_ _date" : {"type" : "date"},"post_ date" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"title" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}}}}}} }

這里我們并沒有為索引文檔的數(shù)據(jù)結(jié)構(gòu)做定義,但是我們發(fā)現(xiàn)es自動創(chuàng)建了?index?type?以及type對應(yīng)的mapping(dynamic mapping)?說明ElasticSearch能根據(jù)我們給的數(shù)據(jù)自動檢測并且給定字段的數(shù)據(jù)類型

如果給定的? true? 、false------>boolean

如果給定的字符串 "字符串"------>string(注意我這里用的是6.8.6版本?string已經(jīng)被text或者keyword代替)

如果給定的數(shù)字? ?1、2------>long

如果給定的小數(shù)? 12.34------>double

如果給定的時間? ?2020-03-14------->date

什么是映射mapping?

mapping定義了type中的每個字段的數(shù)據(jù)類型以及這些字段的如何分詞的等相關(guān)屬性

我們現(xiàn)在帶查詢一下添加的文檔內(nèi)容 GET /myindex/article/_search

{"took" : 29,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 3,"max_score" : 1.0,"hits" : [{"_index" : "myindex","_type" : "article","_id" : "2","_score" : 1.0,"_source" : {"post_ date" : "2020-03-14","title" : "html","content" : "I like html","author_ id" : 120}},{"_index" : "myindex","_type" : "article","_id" : "1","_score" : 1.0,"_source" : {"post_ date" : "2020-03-14","title" : "Java","content" : "java is the best language","author_ id" : 119}},{"_index" : "myindex","_type" : "article","_id" : "3","_score" : 1.0,"_source" : {"post_ _date" : "2020-03-14","title" : "es","content" : "Es is distributed document store","author_ id" : 110}}]} }

?

帶條件的查詢

#查不出來
GET /myindex/article/_search?q=post_date:2020

?

#可以查出來
GET /myindex/article/_search?q=post_date:2020-03-14

{"took" : 4,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 3,"max_score" : 1.0,"hits" : [{"_index" : "myindex","_type" : "article","_id" : "2","_score" : 1.0,"_source" : {"post_date" : "2020-03-14","title" : "html","content" : "I like html","author_id" : 120}},{"_index" : "myindex","_type" : "article","_id" : "1","_score" : 1.0,"_source" : {"post_date" : "2020-03-14","title" : "Java","content" : "java is the best language","author_id" : 119}},{"_index" : "myindex","_type" : "article","_id" : "3","_score" : 1.0,"_source" : {"post_date" : "2020-03-14","title" : "es","content" : "Es is distributed document store","author_id" : 110}}]} }

?

#可以查出來
GET /myindex/article/_search?q=content:html

?

?

注意?

這是因?yàn)镋lasticSearch映射mapping進(jìn)行指定的,post_date是日期類型,而content是字符串類型所以字符串就查詢出來了。像日期date類型和數(shù)字long類型要進(jìn)行精確查詢才可以查詢,而說明日期和數(shù)字類型沒有進(jìn)行分詞,而字符串進(jìn)行了分詞。字符串text類型默認(rèn)進(jìn)行了分詞的

?

到這里我們知道了mapping有兩個作用,一是規(guī)定自定的類型,二是規(guī)定相關(guān)字段的屬性(比如是不是進(jìn)行分詞)


?

?

?

?

總結(jié)

以上是生活随笔為你收集整理的ElasticSearch关于映射mapping介绍的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。