Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法索引JSON文档_Json_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Json,elasticsearch" /> elasticsearch,Json,elasticsearch" />

无法索引JSON文档

无法索引JSON文档,json,elasticsearch,Json,elasticsearch,我有一个json文档,我想索引它 但当我尝试为文件编制索引时,总是会出现错误 我的json文档名为file.json--- 我试图像这样索引json文件--- {“错误”:“RemoteTransportException[[Klaatu][inet[/192.168.1.127:9300]][index:data/write/index]]; 嵌套:MapperParsingException[解析失败,文档为空]; “,“状态”:400} 我也试过这样做---- {“错误”:“Elastic

我有一个json文档,我想索引它

但当我尝试为文件编制索引时,总是会出现错误

我的json文档名为file.json---

我试图像这样索引json文件---

{“错误”:“RemoteTransportException[[Klaatu][inet[/192.168.1.127:9300]][index:data/write/index]]; 嵌套:MapperParsingException[解析失败,文档为空]; “,“状态”:400}

我也试过这样做----

{“错误”:“ElasticsearchParseException[未能派生 xcontent],“status”:400}


我如何索引我的文档,任何人都知道如何解决这个问题

首先确保您的file.json仅包含
\u源
内容,而不包含
\u索引
\u类型
等。因此,在file.json中,您应该只包含以下内容:

{
    "content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ",
    "source": "hello.com",
    "type": "sports",
    "guid": "p1486f499782beb828d870f4a92831720e048514f",
    "language": "en"
}
然后你可以像这样索引它

curl -XPOST 'localhost:9200/myIndex/myType/p1486f499782beb828d870f4a92831720e048514f' --data-binary @file.json
curl -XPOST 'localhost:9200/_bulk' --data-binary @file.json
如果要使用,则file.json需要稍有不同:

{"index":{"_index":"myIndex", "_type":"myType", "_id": "p1486f499782beb828d870f4a92831720e048514f"}}
{"content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ", "source": "hello.com", "type": "sports", "guid": "p1486f499782beb828d870f4a92831720e048514f", "language": "en" }
注意:确保文件以换行符结尾。上例中没有出现换行符

然后你可以像这样发送

curl -XPOST 'localhost:9200/myIndex/myType/p1486f499782beb828d870f4a92831720e048514f' --data-binary @file.json
curl -XPOST 'localhost:9200/_bulk' --data-binary @file.json

因此,底线是,当通过文件发送文档内容时,您需要使用
--数据二进制
而不是
-d

@Great:),非常感谢Val:),它的工作原理与您所解释的一样:)
确保以换行字符结束文件。这才是真正的罪魁祸首
curl -XPOST 'localhost:9200/_bulk' --data-binary @file.json