我是Elasticearch的新手,我已经尝试了2天将一些数据插入到Elasticearch中.我在Google上发现有很多页面可以帮助创建一个索引(我不清楚"索引",它是否意味着"插入"在其他方面?)然后很多地方给出一些curl命令,我真的不知道在哪里执行这些代码行来插入数据.例:
curl -XPOST "http://[localhost]:9200/indexname/typename/optionalUniqueId" -d '{ "field" : "value" }'
Run Code Online (Sandbox Code Playgroud)
我正在使用Window 7,我已经安装了Java并成功运行了elasticsearch.有人可以向我展示有关如何将数据插入Elasticearch的更多细节
非常感谢
Sab*_*san 70
您必须先curl在PC中安装二进制文件.你可以从这里下载.
之后将其解压缩到一个文件夹中.让我们说C:\curl.在该文件夹中,您将找到curl.exe包含多个.dll文件的文件.
现在通过键入cmd来打开命令提示符start menu.并cd c:\curl在那里键入,它将带你到curl文件夹.现在执行curl您拥有的命令.
有一点,Windows不支持围绕字段的单引号.所以你必须使用双引号.例如,我已经将curl命令转换为适当的curl命令.
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/indexname/typename/optionalUniqueId" -d "{ \"field\" : \"value\"}"
Run Code Online (Sandbox Code Playgroud)
小智 13
如果您将 KIBANA 与 elasticsearch 一起使用,那么您可以使用下面的 REST 请求来创建并放入索引。
创建索引:
http://localhost:9200/company
PUT company
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
},
"mappings": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "text",
"analyzer": "analyzer-name"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
创建文档:
POST http://localhost:9200/company/employee/2/_create
{
"name": "Hemani",
"age" : 23,
"experienceInYears" : 2
}
Run Code Online (Sandbox Code Playgroud)
Bla*_*POP 12
让我解释清楚..如果你熟悉rdbms ..索引是数据库..而索引类型是表..它的意思是索引是索引类型的集合.,像表的集合作为数据库(DB).
在NOSQL中.索引是数据库,索引类型是集合.作为数据库集合的集合..
要执行这些查询...需要安装CURL for Windows.
Curl只是一个命令行休息工具..如果你想要一个图形工具..试试
Chrome的Sense插件......
希望能帮助到你..
要测试和尝试Windows的curl请求,可以使用Postman客户端Chrome扩展程序。它非常易于使用且功能强大。
或者按照建议,您可以安装cURL util。
样本卷曲请求如下。
curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"user" : "Arun Thundyill Saseendran",
"post_date" : "2009-03-23T12:30:00",
"message" : "trying out Elasticsearch"
}' "http://10.103.102.56:9200/sampleindex/sampletype/"
Run Code Online (Sandbox Code Playgroud)
我也正在广泛地探索和探索ES。因此,如果您还有其他疑问,请告诉我。
编辑:将索引名称和类型名称更新为完全小写,以避免出现错误并遵循约定。