elasticsearch添加和修改索引

TwoAdmin 2025-10-11 144 10/11

添加索引

#!/bin/bash


curl -X PUT "https://localhost:9200/hs-public-opinion" \
  -k \
  -u elastic:qKvR98F7HWKhcsGfepB4 \
  -H 'Content-Type: application/json' \
  -d'
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "refresh_interval": "1s"
  },
  "mappings": {
    "properties": {
      "id": { "type": "keyword" },
      "title": {
        "type": "text",
        "analyzer": "standard", 
        "fields": {
          "keyword": { "type": "keyword" }
        }
      },
      "content": { "type": "text", "analyzer": "standard" },
      "content_vector": {"type": "dense_vector","dims": 1024,"index": true,"similarity": "cosine"},
      "ctime": { "type": "date", "format": "epoch_second" },
      "created_at": { "type": "keyword" },
      "is_summarized": { "type": "boolean" },
      "content_hash": { "type": "keyword" }
    }
  }
}
'

查看索引

curl -k -u elastic:qKvR98F7HWKhcsGfepB4 "https://localhost:9200/_cat/indices?v"

修改索引字段

# 如果索引已存在,只添加新字段
curl -X PUT "https://localhost:9200/hs-public-opinion" \
  -k \
  -u elastic:qKvR98F7HWKhcsGfepB4 \
  -H 'Content-Type: application/json' \
  -d'
{
  "properties": {
    "content_vector": {
      "type": "dense_vector",
      "dims": 1024,
      "index": true,
      "similarity": "cosine"
    }
  }
}
'

 

- THE END -

TwoAdmin

12月05日17:11

最后修改:2025年12月5日
0

非特殊说明,本博所有文章均为博主原创。