elasticsearch - Elasticsearch创建索引-失败

标签 elasticsearch curl

curl -H "Content-Type: application/json" -XPOST 'https://mydomain/' -d @cps_index.json



JSON文件中的内容
{
"settings": {
    "mappings": {
        "_source": {
            "enabled": false
        },
        "cps": {
            "properties": {
                "firstName": {
                    "type": "text"
                },
                "lastname": {
                    "type": "text"
                },
                "email": {
                    "type": "text"
                },
                "mobileNumber": {
                    "type": "keyword"
                },
                "employeeId": {
                    "type": "keyword"
                }
            }
        }
    }
}

}

失败,响应消息为{“error”:“uri [/]和方法[POST]的HTTP方法不正确,允许:[GET,HEAD,DELETE]”,“状态”:405}

最佳答案

几个问题:

  • 没有索引名称
  • 使用PUT而不是POST
  • mappings嵌套在settings

  • 改为这样做:

    像这样修改cps_index.json:
    {
        "mappings": {
            "doc": {
                "_source": {
                    "enabled": false
                },
                "properties": {
                    "firstName": {
                        "type": "text"
                    },
                    "lastname": {
                        "type": "text"
                    },
                    "email": {
                        "type": "text"
                    },
                    "mobileNumber": {
                        "type": "keyword"
                    },
                    "employeeId": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
    

    运行这个:
    curl -H "Content-Type: application/json" -XPUT 'https://mydomain/indexname'
                                               ^                        ^
                                               |                        |
                                            use PUT              add index name
    

    关于elasticsearch - Elasticsearch创建索引-失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56083315/

    相关文章:

    curl - 如何从 cURL 命令实现 jmeter 请求发布

    python - 如何使用 Python Client Rancher 调用电话

    amazon-web-services - Logstash 和 Elasticsearch 版本不兼容问题?

    python - 如何使用Elasticsearch库为python自动生成索引名?

    elasticsearch - Elasticsearch 查询多个条件

    php - 使用 phpcurl 模拟浏览器在 eBay 中不起作用

    elasticsearch - 如何通过一个 API 调用将多个文档发送到 elastic

    .net - Serilog 不适用于 Elasticsearch

    PHP cURL - 处理信用卡交易时的安全性

    linux - 在 linux 机器上安装 curl-loader