【问题标题】:Elastic Search Create Index - Failed弹性搜索创建索引 - 失败
【发布时间】:2019-09-28 16:48:34
【问题描述】:

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]","status":405 }

【问题讨论】:

    标签: elasticsearch curl


    【解决方案1】:

    需要在https://mydomain后面加上索引名

    https://mydomain/indexname
    

    【讨论】:

    • 我这样做了,我收到了这个错误 {"error":{"root_cause":[{"type":"mapper_parsing_exception","re​​ason":"根映射定义有不受支持的参数: ......,"状态":400}
    • 看起来它需要一些类型名称。但是由于 ES 弃用了该类型。我不想使用类型。我能在这里做什么。谢谢
    【解决方案2】:

    几个问题:

    • 没有索引名称
    • 使用 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
    

    【讨论】:

    • 我使用的是 6.5 版本,当我使用上面的 json 时。它仍然会引发错误。相反,我使用了它并且它起作用了 { "mappings": { "_doc": { "_source": { "enabled": false }, "properties": { "firstName": { "type": "text" }, " lastName”:{“type”:“text”},“email”:{“type”:“text”},“mobileNumber”:{“type”:“keyword”},“employeeId”:{“type”: “关键字” } } } } }
    • 是的,我的错,_source gores 在映射类型中。固定
    猜你喜欢
    • 2020-10-09
    • 2022-08-17
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    相关资源
    最近更新 更多