[英]CURL not working well with docker-compose, Elasticsearch and Windows 10
下面列出了我的 docker-compose.yml 文件。 这就是我要的:
这是我到目前为止得到的:
version: '3'
services:
b-elastic:
image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
container_name: b-elastic
environment:
- discovery.type=single-node
volumes:
- ./dockerelastic:/usr/share/elasticsearch/data
- ./:/project
ports:
- 9200:9200
我可以验证 setupfile 是否存在:
$ docker exec -it b-elastic vi /project/database/elasticsearch/setup.json
给出:
{
"settings": {
"index" : {
"max_ngram_diff": "3"
},
"analysis": {
"analyzer": {
"username_analyzer": {
"tokenizer": "username_tokenizer",
"filter": [
"lowercase"
]
}
},
"tokenizer": {
"username_tokenizer": {
"type": "ngram",
"min_gram": "1",
"max_gram": "4"
}
}
}
},
"mappings": {
"properties": {
"_all" : { "enabled" : false },
"username": {
"type": "text",
"analyzer": "username_analyzer"
}
}
}
}
现在我想在 Elasticsearch 上执行 setup.json:
$ docker exec -it b-elastic curl -X PUT http://localhost:9200/users -H "Content-Type: application/json" --data-binary @project/database/elasticsearch/setup.json
这是 Docker 返回的内容:
Warning: Couldn't read data from file
Warning: "project/database/elasticsearch/setup.json", this makes an empty
Warning: POST.
{"acknowledged":true,"shards_acknowledged":true,"index":"users"}
看起来它已被确认,但是当我尝试搜索用户时,我收到此错误:
[match] analyzer [username_analyzer] not found
将 setup.json 的内容复制粘贴到 Postman 并在那里执行请求时,我没有收到此错误。
如何通过 Windows 上的 Elasticsearch 容器中的卷执行文件?
编辑:接受的答案有效,但请注意,在使用 PowerShell 执行命令时它失败了。 命令提示符有效。
看起来 curl 无法读取您的 setup.json 文件,因此它创建了一个空索引。
请注意,当您使用 vi 时,您使用的是绝对路径(/ 在开头),但是当您使用 curl 时,您没有使用。 尝试
docker exec -it b-elastic curl -X PUT http://localhost:9200/users -H "Content-Type: application/json" --data-binary @/project/database/elasticsearch/setup.json
这不是,看看它是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.