将 JSON 文件导入/索引到 Elasticsearch [英] Import/Index a JSON file into Elasticsearch

查看:70
本文介绍了将 JSON 文件导入/索引到 Elasticsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Elasticsearch 的新手,到目前为止一直在手动输入数据.例如我做了这样的事情:

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"
}'

我现在有一个 .json 文件,我想将它索引到 Elasticsearch 中.我也尝试过类似的方法,但没有成功:

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 文件?我需要先采取哪些步骤来确保映射正确?

How do I import a .json file? Are there steps I need to take first to ensure the mapping is correct?

推荐答案

如果您想使用带有 curl 的文件,正确的命令是:

The right command if you want to use a file with curl is this:

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

Elasticsearch 是无模式的,因此您不一定需要映射.如果您按原样发送 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.

如果你想通过命令行与 Elasticsearch 交互,你可能想看看 elasticshell 应该比 curl 方便一点.

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:需要注意的是自定义映射类型 已弃用,不应使用.我更新了上面 url 中的类型,以便更容易地看到哪个是索引,哪个是类型,因为将两者都命名为test"令人困惑.

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 文件导入/索引到 Elasticsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆