I am new to Elasticsearch and have been entering data manually up until this point. For example I've done something like this:

$ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elastic Search"
}'

I now have a .json file and I want to index this into Elasticsearch. I've tried something like this too, but no success:

curl -XPOST 'http://jfblouvmlxecs01:9200/test/test/1' -d lane.json

我如何导入一个文件.json文件?我需要先采取哪些步骤来确保映射正确吗?

推荐答案

如果要将文件与curl一起使用,正确的命令是:

curl -XPOST 'http://jfblouvmlxecs01:9200/test/_doc/1' -d @lane.json

Elasticsearch is schemaless, therefore you don't necessarily need a mapping. If you send the json as it is and you use the default mapping, every field will be indexed and analyzed using the standard analyzer.

If you want to interact with Elasticsearch through the command line, you may want to have a look at the elasticshell which should be a little bit handier than curl.

2019-07-10: Should be noted that custom mapping types is deprecated and should not be used. I updated the type in the url above to make it easier to see which was the index and which was the type as having both named "test" was confusing.

Json相关问答推荐

嵌套自定义解组

基于两个条件替换扁平化的SON中的值

2020-12年草案中的Json列举模式

使用Jolt将字符串数组转换为JSON对象数组

规范化JSON数据

如何强制仅有一个元素的数组在JSON中生成方括号

如何在 jq 中按 IP 地址排序?

如何使用 jq 将字符串数组转换为对象?

Shell脚本空格转义

使用 KQL 和外部 data() 运算符从 json 文件中提取信息

从 PowerShell 编辑 Windows 终端配置文件设置 JSON

如何将从嵌套 Select 返回的空值转换为空数组?

如何删除 django jsonfield 中的特定项目

Jackson 动态属性名称

在 Rails 3 中处理 JS/ERB 模板中的 JSON

Jackson:忽略 Json 配置值

与classic 规范化表相比,postgres JSON 索引是否足够高效?

Spring restTemplate 获取原始 json 字符串

杰克逊在通用列表中读取 json

ASP.NET Web API JSON 输出中没有时间的日期