1)字符串
2)数值型:long, integer, short, byte, double, float, half_float, scaled_float
3)布尔:boolean
4)二进制:binary(该类型的字段把值当做经过 base64 编码的字符串,默认不存储,且不可搜索)
5)范围类型
6)日期:date
PUT localhost:9200/nba/_mapping { "properties":{ "name":{ "type":"text" }, "team_name":{ "type":"text" }, "position":{ "type":"text" }, "play_year":{ "type":"long" }, "jerse_no":{ "type":"keyword" }, "title":{ "type":"text" }, "date":{ "type":"date" } } } POST localhost:9200/nba/_doc/4 { "name":"蔡x坤", "team_name":"勇士", "position":"得分后卫", "play_year":10, "jerse_no":"31", "title":"打球最帅的明星", "date":"2020-01-01" } POST localhost:9200/nba/_doc/5 { "name":"杨超越", "team_name":"猴急", "position":"得分后卫", "play_year":10, "jerse_no":"32", "title":"打球最可爱的明星", "date":1610350870 } POST localhost:9200/nba/_doc/6 { "name":"吴亦凡", "team_name":"湖人", "position":"得分后卫", "play_year":10, "jerse_no":"33", "title":"最会说唱的明星", "date":1641886870000 }
1)数组类型 Array
2)对象类型 Object
对象类型可能有内部对象
POST localhost:9200/nba/_doc/8 { "name":"吴亦凡", "team_name":"湖人", "position":"得分后卫", "play_year":10, "jerse_no":"33", "title":"最会说唱的明星", "date":"1641886870", "array":[ "one", "two" ], "address":{ "region":"China", "location":{ "province":"GuangDong", "city":"GuangZhou" } } } 索引方式 "address.region": "China", "address.location.province": "GuangDong", "address.location.city": "GuangZhou" POST localhost:9200/nba/_search { "query":{ "match":{ "address.region":"china" } } }
IP类型:IP类型的字段用于存储IPv4或IPv6的地址, 本质上是一个长整型字段.
POST localhost:9200/nba/_mapping { "properties":{ "name":{ "type":"text" }, "team_name":{ "type":"text" }, "position":{ "type":"text" }, "play_year":{ "type":"long" }, "jerse_no":{ "type":"keyword" }, "title":{ "type":"text" }, "date":{ "type":"date" }, "ip_addr":{ "type":"ip" } } } PUT localhost:9200/nba/_doc/9 { "name":"吴亦凡", "team_name":"湖人", "position":"得分后卫", "play_year":10, "jerse_no":"33", "title":"最会说唱的明星", "ip_addr":"192.168.1.1" } POST localhost:9200/nba/_search { "query":{ "term":{ "ip_addr":"192.168.0.0/16" // (192.168.0.0~192.168.255.255) } } }
原文:https://www.cnblogs.com/jwen1994/p/12639244.html