【发布时间】:2015-12-15 07:16:57
【问题描述】:
我创建了一个 bash 脚本来测试我的索引,但是这个 bash 脚本给出的结果与我直接在终端中复制 CURL 命令不同。我检索到的结果与使用 sh [file-name] 启动代码时不同会发生什么?
#!/bin/sh
alias curl="curl -s"
echo "Delete index"
curl -X DELETE "localhost:9200/products?pretty"
echo
echo "Create index"
curl -X POST "localhost:9200/products?pretty" -d '
{
"products" : {
"settings" : {
"index" : {
"analysis" : {
"filter" : {
"my_synonym" : {
"ignore_case" : "true",
"expand" : "true",
"type" : "synonym",
"synonyms" : [ "pote, foundation"] }
},
"analyzer" : {
"folding_analyzer" : {
"filter" : [ "standard", "lowercase", "asciifolding", "my_synonym" ],
"tokenizer" : "standard"
}
}
},
"number_of_shards" : "1",
"number_of_replicas" : "0"
}
},
"mappings" : {
"product" : {
"dynamic" : "false",
"properties" : {
"brand_name" : {
"type" : "string",
"index_options" : "offsets",
"analyzer" : "folding_analyzer"
},
"product_name" : {
"type" : "string",
"index_options" : "offsets",
"analyzer" : "folding_analyzer"
}
}
}
}
}
}
'
echo
echo "Info index"
curl -XGET 'localhost:9200/products/_settings,_mappings?pretty'
echo
echo "Test doc:"
curl -X POST "localhost:9200/products/product/1?pretty" -d '{
"product_name": "Foundation Brush",
"brand_name": "Bobbi Brown"
}'
echo
echo "Test doc:"
curl -X POST "localhost:9200/products/product/2?pretty" -d '{
"product_name": "Foundation Primer",
"brand_name": "Laura Mercier"
}'
echo
echo "Test doc:"
curl -X POST "localhost:9200/products/product/3?pretty" -d '{
"product_name": "Lock-It Tattoo Foundation",
"brand_name": "Kat Von D"
}'
echo
echo "Test doc:"
curl -X POST "localhost:9200/products/product/4?pretty" -d '{
"product_name": "Diorskin Airflash Spray Foundation",
"brand_name": "Dior"
}'
echo
echo "Test doc:"
curl -X POST "localhost:9200/products/product/5?pretty" -d '{
"product_name": "Diorskin Airflash Spray Lancôme",
"brand_name": "Dior"
}'
echo
echo "Info index"
curl -XGET 'localhost:9200/products/_settings,_mappings?pretty'
echo
echo "Search all"
curl -X GET "localhost:9200/products/_search?pretty" -d '{
"query": {
"match_all": {}
}
}'
echo
【问题讨论】:
-
你已经发布了很多 curl 命令。你能解释一下哪一个导致不同的输出,有什么区别吗?也许只选择一个 curl 请求作为示例。
标签: bash shell elasticsearch terminal sh