1.type
string
索引分析(index):analyzed(默认)、not_analyzed、no
存储(store): true(独立存储)、false(默认)不存储。
Numeric
包括 long、integer、short、byte等·
索引分析(index):not_analyzed(默认)、no
存储:同string
date
日期类型
索引分析(index):not_analyzed(默认)、no
存储(store): true(独立存储)、false(不存储默认)
格式化(format): 解析日期格式
"date": {
"type": "date",
"format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
nested vs Object
nested(嵌套类型):构造数组,里面有多个为json格式的嵌套对象,保持每个嵌套的对象的内容相关联
Object(内部对象默认):被扁平化处理,字段 之间的相关性已经丢失了,因为每个多值域只是一包无序的值,而不是有序数组。
例:
nest结构:
这里的stable_ts为nested结构,weekdays和times相关联,绑定在一起。
Object结构:
{
"followers.age": [19, 26, 35],
"followers.name": [alex, jones, lisa, smith, mary, white]
}
age与name没有绑定一起。
Text vs keyword
Text:会分词,然后进行索引
支持模糊、精确查询
不支持聚合
keyword:不进行分词,直接索引
支持模糊、精确查询
支持聚合
2. index
analyzed:
利用解析器,一般在string中用到,比如分词,然后索引
not_analyzed:
不采用任何解析器,精确索引
no:
不索引
例:
3.analyzer
standard: 默认分词器。
whitespacce: 空格为分隔符
simple: 空格,标点符号,数字作为分割符
stop: 分词使用默认stopwords(english)
keyword: 不分词
例:
POST _analyze
{
"analyzer": "standard",
"text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
}
返回:
{
"tokens": [
{
"token": "the",
"start_offset": 0,
"end_offset": 3,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "2",
"start_offset": 4,
"end_offset": 5,
"type": "<NUM>",
"position": 1
},
{
"token": "quick",
"start_offset": 6,
"end_offset": 11,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "brown",
"start_offset": 12,
"end_offset": 17,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "foxes",
"start_offset": 18,
"end_offset": 23,
"type": "<ALPHANUM>",
"position": 4
},
{
"token": "jumped",
"start_offset": 24,
"end_offset": 30,
"type": "<ALPHANUM>",
"position": 5
},
{
"token": "over",
"start_offset": 31,
"end_offset": 35,
"type": "<ALPHANUM>",
"position": 6
},
{
"token": "the",
"start_offset": 36,
"end_offset": 39,
"type": "<ALPHANUM>",
"position": 7
},
{
"token": "lazy",
"start_offset": 40,
"end_offset": 44,
"type": "<ALPHANUM>",
"position": 8
},
{
"token": "dog's",
"start_offset": 45,
"end_offset": 50,
"type": "<ALPHANUM>",
"position": 9
},
{
"token": "bone",
"start_offset": 51,
"end_offset": 55,
"type": "<ALPHANUM>",
"position": 10
}
]
}