elasticsearch创建索引和查看索引及结构命令

本文详细介绍了如何使用Elasticsearch进行索引配置,包括查看索引结构、创建索引、设置分片与副本数量,以及定义字段类型和属性。通过具体的示例,展示了如何为不同类型的字段设置映射,如文本、日期、数字等,同时提供了curl命令用于索引的创建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

命令

查看索引及结构:

命令: GET /索引名/_mapping?pretty

创建索引:

命令: PUT 索引名

示例:
number_of_shards:分片数量(按机器节点数量计算,创建后不能更改)
number_of_replicas:副本数量

PUT admin_log_0821
{
	  "settings":{
	    "number_of_shards":6,
      "number_of_replicas":	1
	  },
		"mappings": {
			"logs": {
				"properties": {
				"esCreateTime": {
					"type": "long"
				},
				"id": {
					"type": "long"
				},
				"ip": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				},
				"uri": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				},
				"userId": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				},
				"userName": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				}
			}
			}
		}
	}

基础索引示例:

{
  "settings": {
    "number_of_shards": 16,
    "number_of_replicas": 1
  },
  "mappings": {
    "risk_event_ads": {
      "dynamic": "strict",
      "properties": {
        "flowNo": {
          "type": "String",
          "index": "not_analyzed"
        },
        "elapseTime": {
          "type": "long"
        },
        "ipLon": {
          "type": "float"
        },
        "createTime": {
          "type": "date"
        },
        "occurTimeYear": {
          "type": "short"
        },
        "occurTimeMonth": {
          "type": "byte"
        },
        "cpuCurFreq": {
          "index": "not_analyzed",
          "type": "string"
        },
        "extraInfoObj": {
          "type": "object",
          "dynamic": true
        }
      }
    }
  }
}

crul命令: curl -XPUT “http://es地址:9200/索引名” -H ‘Content-Type: application/json’ -d’索引json’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值