1.ElasticSearch是面向文档的,文档是所有可搜索数据的最小单位
·日志文件中的日志项
·一本电影的具体信息/一张唱片的详细信息
·MP3播放器里面的一首歌/一遍PDF文档中的具体内容
2.文档是会被序列化成JSON格式,报错在ElasticSearch中
·JSON对象由字段组成
·每个字段都有对应的字段类型(字符串/数值/布尔/日期/二进制/范围类型)
3.每个文档都有一个Unique ID
·你可以自己指定ID
·或者通过ElasticSearch自动生成
一篇文档包含了一系列的字段,类似数据库表中一条记录
JSON文档格式灵活不需要预先定义格式
·字段的类型可以指定或者通过ElasticSearch自动推算
·支持数组/支持嵌套
{
"_index": "my_test_index",
"_type": "test_idnex",
"_id": "AXcpGrIeEQcMCfQJ7Gc5",
"_score": 1,
"_source": {
"testId": "4",
"testName": "zhaoliu"
}
}
元数据,用于标准文档的相关信息
{
"my_test_index": {
"settings": {
"index": {
"search": {
"slowlog": {
"level": "info",
"threshold": {
"fetch": {
"warn": "200ms",
"trace": "50ms",
"debug": "80ms",
"info": "100ms"
},
"query": {
"warn": "200ms",
"trace": "50ms",
"debug": "80ms",
"info": "100ms"
}
}
}
},
"indexing": {
"slowlog": {
"level": "info",
"threshold": {
"index": {
"warn": "200ms",
"trace": "20ms",
"debug": "50ms",
"info": "100ms"
}
},
"source": "1000"
}
},
"number_of_shards": "5",
"provided_name": "my_test_index",
"creation_date": "1611301841428",
"unassigned": {
"node_left": {
"delayed_timeout": "5m"
}
},
"number_of_replicas": "1",
"uuid": "e5B65ySmQ-GE8Tj9gUHIPw",
"version": {
"created": "5050399"
}
}
}
}
}
RDBMS | ElasticSearch |
---|---|
Table | Index(Type) |
Row | Document |
Column | Filed |
Schema | Mapping |
SQL | DSL |
节点类型 | 配置参数 | 默认值 |
---|---|---|
maste eligible | node.master | true |
data | node.data | true |
ingest | node.ingest | true |
coordinating only | 无 | 每个节点默认都是coordinating 节点设置其他类型全部为false |
machine learning | node.ml | true(需enable x-pack) |
shard也是一种资源,shard过多会影响集群的稳定性。因为shard过多,元信息会变多,这些元信息会占用堆内存。shard过多也会影响读写性能,因为每个读写请求都需要一个线程。所以如果index没有很大的数据量,不需要设置很多shard。
)的问题
GET _cluster/health
{
"cluster_name": "es-cn-zz11rb9fv000fj1pe",
"status": "green",
"timed_out": false,
"number_of_nodes": 6,
"number_of_data_nodes": 3,
"active_primary_shards": 766,
"active_shards": 1507,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 100
}
GET _cat/nodes
172.17.25.39 45 91 3 0.23 0.08 0.06 di - 3Ja7gZv
172.17.25.53 55 79 1 0.00 0.01 0.05 mi * H1guebi
172.17.25.52 22 78 0 0.01 0.02 0.05 mi - rdjzfmG
172.17.25.51 24 78 0 0.00 0.01 0.05 mi - uaU255o
172.17.25.38 54 91 2 0.23 0.26 0.16 di - wQwmOos
172.17.25.40 65 89 1 0.01 0.17 0.26 di - 4mZ8XK7
GET _cat/shard
companyinfo 4 r STARTED 31408061 38.5gb 172.17.25.38 wQwmOos
companyinfo 4 p STARTED 31408061 40.2gb 172.17.25.39 3Ja7gZv
companyinfo 1 p STARTED 31412834 43.2gb 172.17.25.38 wQwmOos
companyinfo 1 r STARTED 31412834 41.7gb 172.17.25.39 3Ja7gZv
companyinfo 3 r STARTED 31407535 37.6gb 172.17.25.40 4mZ8XK7
companyinfo 3 p STARTED 31407535 36.8gb 172.17.25.39 3Ja7gZv
companyinfo 2 r STARTED 31412927 41.8gb 172.17.25.40 4mZ8XK7
companyinfo 2 p STARTED 31412927 41.2gb 172.17.25.39 3Ja7gZv
companyinfo 0 p STARTED 31400572 40.4gb 172.17.25.40 4mZ8XK7
companyinfo 0 r STARTED 31400572 43.1gb 172.17.25.38 wQwmOos
PUT my_test_index/_doc/1
{
"user":"mike",
"comment":"You know,for search"
}
PUT my_test_index/_create/1
{
"user":"mike",
"comment":"You know,for search"
}
POST my_test_index/_doc (不指定ID 自动生成)
{
"user":"mike",
"comment":"You know,for search"
}
GET my_test_indx/_doc/_1
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_store",
"_type": "products",
"_id": "5",
"_score": 1,
"_source": {
"price": 10,
"productName": "ZHANGSAN",
"productID": "XHDK-A-1293-#fJ3"
}
}
]
}
POST my_test_index/_update/1
{
"doc":{
"user":"mike",
"comment":"You know,ElasticSearch"
}
}
DELETE my_test_index/_doc/1
支持在一次API调用中,对不同的索引进行操作
支持四种类型操作
可以再URI中指定Index 也可以在Payload 中进行
操作中单条操作失败不会影响其他操作
返回结果包括了每一条操作执行的结果
GET /_mget
{
"docs": [{
"_index": "my_store",
"_id": 1
},
{
"_index": "companyinfo",
"_id": "cd5b8daadc31482e84715da912a604f4"
}
]
}
{
"docs": [
{
"_index": "my_store",
"_type": "products",
"_id": "1",
"_version": 4,
"found": true,
"_source": {
"price": 12,
"productID": "XHDK-A-1293-#fJ3"
}
},
{
"_index": "companyinfo",
"_type": "companyinfo",
"_id": "cd5b8daadc31482e84715da912a604f4",
"_version": 1,
"found": true,
"_source": {
"entName": "广西金朋豪友投资有限公司",
"orgLogo": "",
"regCapital": "500万元人民币",
"city": "广西壮族自治区",
"regDate": "2017-05-17",
"industry": "商务服务业",
"taxpayerIdNo": "91450800MA5L585X6F",
"creditCode": "91450800MA5L585X6F",
"registrationAuthority": "贵港市市场监督管理局",
"staffSize": "",
"orgCode": "MA5L585X-6",
"enterpriseStatus": "存续(在营、开业、在册)",
"id": "cd5b8daadc31482e84715da912a604f4",
"businessRegCode": "450800000151505",
"email": "",
"introduction": "",
"regCapitalNumber": 500,
"website": "",
"address": "贵港市解放北路龙圣新村小区(四小区213号)一楼",
"town": "",
"bossId": "4b12e1b8d1ef11-p-4b12e276d1ef1",
"corporation": "蒙雪",
"businessScope": "对文化产业、旅游业、旅游商品的投资;对建筑业的投资;企业形象策划,市场营销策划,赛事活动策划,舞台造型策划,婚礼庆典活动策划;展览展示服务,会务服务,礼仪服务,摄影服务;网络信息技术的开发、咨询、转让服务;影视策划咨询,企业管理咨询,投资信息咨询(以上项目除国家有专项规定外);电视节目制作服务(具体项目以审批部门批准为准);动漫设计;出版物的零售(具体项目以审批部门批准为准),室内外装饰装修工程,建筑工程设计,市政工程,景观工程设计(以上项目凭资质证经营);餐饮服务(具体项目以审批部门批准为准);设计、制作、代理、发布国内各类广告;演出经纪(具体项目以审批部门批准的为准);政府采购、招投标代理、工程咨询、土地评估、房地产评估、资产评估、房地产评估审计、工程预结算。",
"businessTerm": "长期",
"contributedcapital": "",
"checkDate": "2017-05-17",
"enterpriseType": "有限责任公司(自然人独资)",
"orgNameEn": "",
"taxpayerQualification": "",
"telphone": "",
"district": "",
"sameEnterprise": "<关联企业3>",
"oldOrgName": "",
"readAddress": "贵港市解放北路龙圣新村小区(四小区213号)一楼",
"contributors": ""
}
}
]
}
问题 | 原因 |
---|---|
无法连接 | 网络故障或集群故障 |
连接无法关闭 | 网络故障或节点出错 |
429 | 集群过于繁忙 |
4XX | 请求体格式有误 |
500 | 集群内部错误 |