我正在尝试将一些数据发布到 flex 搜索服务器。我为此使用curl。代码是:
curl -X PUT https://username:password@someurl:443/index_name?pretty -H 'Content-Type: application/json' -d ' {"mappings": {"properties": {"my_field": {"type": "search_as_you_type"}}}}'
只有通过
cat/_indices?v
检索索引信息的基本内容才有效错误包括
"Content-Type header [application/x-www-form-urlencoded] is not supported", curl: (6) Could not resolve host: application
curl: (3) [globbing] unmatched brace in column 1
curl: (3) [globbing] unmatched brace in column 1
curl: (3) [globbing] unmatched brace in column 1
curl: (3) [globbing] unmatched brace in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 19
最佳答案
很明显,错误消息表明您在错误消息的第一行中使用了错误的内容类型application/x-www-form-urlencoded
。
"Content-Type header [application/x-www-form-urlencoded] is not supported",
由于给定的映射似乎是从官方ES https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-as-you-type.html链接复制而来的,因此只有您可以找到相应的CURL格式。
粘贴该格式以及链接中的屏幕截图,如何复制整个curl命令。
在这里,我在本地尝试过并成功了,请注意,唯一的区别是内容类型应该为
application/json
curl -X PUT "localhost:9500/so_index?pretty" -H 'Content-Type: application/json' -d'
{
"mappings": {
"properties": {
"my_field": {
"type": "search_as_you_type"
}
}
}
}
'
关于elasticsearch - 向 Elasticsearch 服务器发送 curl 请求时,不支持错误application/x-www-form-urlencoded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59677443/