A: Data Types
Core Data Types
Complex data types
Type-specific data
II: Core Data Types
1. String
text: Use the whole index files, the type field word by word into the device ⾏
keyword: regardless of the word, you can only search the full value of the field
2. Numeric
long, integer, short, byte, double, float, half_float, scaled_float
3. Binary
The type of the value field as base64 encoded string through the default is not stored, and not searchable
4. Range Type
⼀ value range type indicates a range, not ⼀ ⽽ a particular value integer_range, float_range, long_range, double_range, date_range
For example age type is integer_range, then the value may be { "gte": 20, "lte": 40}; search "term": { "age": 21} can search for that value
Manufacturing data, and then add:
PUT /wba/ { "mappings": { "properties": { "age_range": { "type": "integer_range" } } } } PUT /wba/_doc/1 { "age_range":{ "gte":10, "lte":15 } } PUT /wba/_doc/2 { "age_range":{ "gte":15, "lte":20 } } PUT /wba/_doc/3 { "age_range":{ "gte":20, "lte":30 } }
Inquire:
GET /wba/_search { "query": { "term":{ "age_range":15 } } }
effect:
{ "took" : 247, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "wba", "_type" : "_doc", "_id" : "1", "_score" : 1.0, "_source" : { "age_range" : { "gte" : 10, "lte" : 15 } } }, { "_index" : "wba", "_type" : "_doc", "_id" : "2", "_score" : 1.0, "_source" : { "age_range" : { "gte" : 15, "lte" : 20 } } } ] } }
5. Type Date
Since no Json date type, so es meets the format defined by the format identification strings to determine whether the type of date
The default format is: strict_date_optional_time || epoch_millis
Format "2022-01-01" "2022/01/01 12:10:30", a string format
Number of milliseconds from the start of epoch (1970 1 Month date 0:00) starting
The number of seconds starting from the beginning of the era
PUT /cba/ { "mappings": { "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" } } } }
adding data
PUT /cba/_doc/1 { "name": "蔡x坤", "team_name": "勇⼠", "Position": "shooting guard" "play_year": 10, "jerse_no": "31", "Title": "play the most handsome star" "date": "2020-01-01" } PUT /cba/_doc/2 { "Name": "Yang Beyond" "team_name": "猴急", "Position": "shooting guard" "play_year": 10, "jerse_no": "32", "Title": "play the most adorable star" "date": 1610350870 }
Direct inquiries:
GET /cba/_search { "query": { "term": { "date": { "value": "2020-01-01" } } } }
result:
{ "took" : 541, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "cba", "_type" : "_doc", "_id" : "1", "_score" : 1.0, "_source" : { "name" : "蔡x坤", "team_name" : "勇⼠", "Position": "shooting guard" "play_year" : 10, "jerse_no" : "31", "Title": "play the most handsome star" "date" : "2020-01-01" } } ] } }
Three: complex data types
1. Array types Array
No special array type ES ⻔ directly with the [] to the definition,
All values in the array must be the same ⼀ data types, do not support mixed data types of array:
String array [ "one", "two"] integer array [1, 2] Object Object array [{ "name": "Louis", "age": 18}, { "name": "Daniel", "age ": 17}]
⼀ same array can store the same type of data can not coexist, such as [10, "some string"] is wrong
2. Object type Object
Object types may have internal objects
{ "name": "吴亦凡", "team_name": "湖⼈", "Position": "shooting guard" "play_year": 10, "jerse_no": "33", "Title": "Most would rap star" "date": "1641886870", "array": [ "one", "two" ], "address": { "region": "China", "location": { "province": "GuangDong", "city": "GuangZhou" } } }
Indexing:
{ "query": { "match": { "address.region": "china" } } }
IV: specific data type
You can refer to: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html#_complex_datatypes