You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何导入特定格式的Elasticsearch数据库定义文件?

How to Import Your Elasticsearch Definitions File

Your file contains three separate Elasticsearch API requests: creating the drafts index, defining its mapping, and setting up the variants index with custom analysis settings. Here are the most straightforward ways to import these into your cluster:

If you have Kibana connected to your Elasticsearch cluster, this is the easiest approach:

  1. Open Kibana and click the Dev Tools icon (wrench symbol) in the left sidebar.
  2. Clear any existing text in the console pane.
  3. Paste your entire file content directly into the console.
  4. Hit the Play button (▶️) or press Ctrl+Enter to run all requests in sequence.
  5. Check the responses below—look for 200 OK or 201 Created statuses to confirm each step worked.

Method 2: Use Curl via a Shell Script

For command-line users without Kibana, wrap each request in a curl command and run them as a script:

  1. Save your original content to a file (e.g., es_setup.txt for reference).
  2. Create a new shell script (e.g., setup_es.sh) with the following code, replacing http://your-es-host:9200 with your actual Elasticsearch cluster URL:
    #!/bin/bash
    ES_URL="http://your-es-host:9200"
    
    # Create the drafts index
    curl -X PUT "$ES_URL/drafts" -H "Content-Type: application/json" -d '{
      "settings": { "max_result_window" : "100000" }
    }'
    
    echo -e "\n---\n"
    
    # Set the draft mapping for the drafts index
    curl -X PUT "$ES_URL/drafts/draft/_mapping" -H "Content-Type: application/json" -d '{
      "draft":{
        "properties":{
          "id":{ "type":"keyword" },
          "analysis_id":{ "type":"keyword" }
        }
      }
    }'
    
    echo -e "\n---\n"
    
    # Create the variants index with custom analysis settings
    curl -X PUT "$ES_URL/variants" -H "Content-Type: application/json" -d '{
      "settings": {
        "analysis": {
          "normalizer": {
            "lowercase_normalizer": {
              "type": "custom",
              "char_filter": [],
              "filter": ["lowercase"]
            }
          }
        },
        "max_result_window" : "100000"
      }
    }'
    
  3. Make the script executable: chmod +x setup_es.sh
  4. Run the script: ./setup_es.sh
  5. Verify each response confirms successful creation or update.

Method 3: Use the Elasticsearch Bulk API

For larger batches of requests, you can use the bulk endpoint by reformatting your file to match its required structure:

  1. Create a new file (e.g., bulk_setup.json) with this formatted content:
    {"put": {"_index": "drafts"}}
    {"settings": { "max_result_window" : "100000" }}
    {"put": {"_index": "drafts", "_type": "draft", "_mapping": true}}
    {"draft":{ "properties":{ "id":{ "type":"keyword" }, "analysis_id":{ "type":"keyword" } } }}
    {"put": {"_index": "variants"}}
    {"settings": { "analysis": { "normalizer": { "lowercase_normalizer": { "type": "custom", "char_filter": [], "filter": ["lowercase"] } } }, "max_result_window" : "100000" }}
    
  2. Send it to Elasticsearch with curl:
    curl -X POST "http://your-es-host:9200/_bulk" -H "Content-Type: application/json" --data-binary @bulk_setup.json
    
  3. Review the bulk response to ensure all operations succeeded.

Key Notes:

  • If your cluster uses authentication, add -u username:password to your curl commands, or log into Kibana with valid credentials.
  • If you get "index already exists" errors, either delete the existing indices first (use DELETE /drafts and DELETE /variants in Dev Tools/curl) or append ?ignore_already_exists=true to your PUT index requests.
  • Ensure your Elasticsearch version supports the settings you’re using (e.g., custom normalizers are available in ES 5.0+).

内容的提问来源于stack exchange,提问作者thondeboer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:39:01