将JSON文件索引到elasticsearch命令/映射错误中



我是ELK的新手,我想将JSON文件导入Elasticsearch。这是我的文件:

{
"news":{
"1":{
"_score":1.0,
"_index":"newsvit",
"_source":{
"content":" u0641u0647u06ccu0645u0647 u062du0633u0646u200cu0645u06ccu0631u06cc: u0627u06afu0631u0686u0647 u062fu0631 u0647u06ccu0627u0647u0648u06cc u0627u0646u062au062eu0627u0628u0627u062a u0631u06ccu0627u0633u062a u062cu0645u0647u0648u0631u06ccu060c u0645u0648u0636u0648u0639u06cc u0645u0627u0646u0646u062f u0645u0639u0631u0641u06cc u06a9u0627u0646u062fu06ccu062fu0627u0647u0627u06cc u0634u0648u0631u0627u06cc u0634u0647u0631 u062fu0631 u062du0627u0634u06ccu0647 u0642u0631u0627u0631 u06afu0631u0641u062au0647u060c u0627u0645u0627 u0627u0645u0633u0627u0644 u0628u0647 u0639u0646u0648u0627u0646 u067eu0646u062cu0645u06ccu0646 u062fu0648u0631u0647 u0627u0646u062au062eu0627u0628 u0627u0639u0636u0627u06cc u0634u0648u0631u0627u06cc u0634u0647u0631u060c u0627u06ccu0646 u0631u0648u06ccu062fu0627u062f u0628u0647 u0646u0633u0628u062a u062fu0648u0631u0647u200cu0647u0627u06cc u0642u0628u0644u060c u0628u06ccu0634u062au0631 u0645u0648u0631u062f u062au0648u062cu0647 u0648u0627u0642u0639 u0634u062fu0647. u0627u06ccu0646 u0627u0642u0628u0627u0644u060c u0686u0647 u0627u0632 u0633u0648u06cc u0686u0647u0631u0647u200cu0647u0627u06cc u0645u0637u0631u062d u0628u0631u0627u06cc u062bu0628u062a u0646u0627u0645 u0648 u0686u0647 u0627u0632 u0633u0648u06cc u0645u0631u062fu0645 u0628u0631u0627u06cc u0645u0634u0627u0631u06a9u062a u062fu0631 u0627u06ccu0646 u0631u0648u06ccu062fu0627u062fu060c u0639u0644u062au200cu0647u0627u06cc u06afu0648u0646u0627u06afu0648u0646u06cc u0645u06ccu200cu062au0648u0627u0646u062f u062fu0627u0634u062au0647 u0628u0627u0634u062f u06a9u0647 u062au0648u062cu0647 u0628u0647 u0622u0646u060c u0645u06ccu200cu062au0648u0627u0646u062f u0631u0627u0647u06afu0634u0627u06cc u0627u0639u0636u0627u06cc u0631u06",
"lead":"u062cu0627u0645u0639u0647 > u0634u0647u0631u06cc - u0645u06ccu0632u06afu0631u062fu06cc u062fu0631u0628u0627u0631u0647 u0639u0645u0644u06a9u0631u062f u062fu0648u0631u0647u200cu0647u0627u06cc u06afu0630u0634u062au0647 u0634u0648u0631u0627u06cc u0634u0647u0631u060c u0622u0646u0686u0647 u0627u0639u0636u0627u06cc u062cu062fu06ccu062f u0628u0627u06ccu062f u0645u062f u0646u0638u0631 u062fu0627u0634u062au0647 u0628u0627u0634u0646u062f u0648 u0647u0645u0686u0646u06ccu0646 u0645u0627u0647u06ccu062a u0633u06ccu0627u0633u06cc u0628u0648u062fu0646 u06ccu0627 u0646u0628u0648u062fu0646 u0634u0648u0631u0627u06cc u0634u0647u0631.",
"agency":"13",
"date_created":1494518193,
"url":"http://www.khabaronline.ir/(X(1)S(bud4wg3ebzbxv51mj45iwjtp))/detail/663749/society/urban",
"image":"uploads/2017/05/11/1589793661.jpg",
"category":"15"
},
"_type":"news",
"_id":"2981643"
},
"2": {
...

根据我所学到的,起初,我试图在Kibana的DevTools中为它创建一个映射系统。我希望能够根据_source中的字段(如类别、id等(对此文件进行查询和搜索。这是我的映射:

PUT /main-news-test-data
{
"mappings": {
"properties": {
"_score": {"type":"integer"},
"_index": {"type":"keyword"},
"_type":{"type":"keyword"},
"_id":{"type":"keyword"} 
},
"_source":{
"properties": {
"content":{"type":"text"},
"title":{"type":"text"},
"lead":{"type":"text"},
"agency":{"type":"keyword"},
"date_created":{"type":"date"},
"url":{"type":"keyword"},
"image":{"type":"keyword"},
"category":{"type":"keyword"}
}
}
}
}
HEAD main-news-test-data
GET /main-news-test-data/_search?q=*

但是当我在Devtools中运行时,我收到了这个错误:

{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "Mapping definition for [_source] has unsupported parameters:  [properties : {image={type=keyword}, agency={type=keyword}, date_created={type=date}, title={type=text}, category={type=keyword}, content={type=text}, lead={type=text}, url={type=keyword}}]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "Failed to parse mapping [_doc]: Mapping definition for [_source] has unsupported parameters:  [properties : {image={type=keyword}, agency={type=keyword}, date_created={type=date}, title={type=text}, category={type=keyword}, content={type=text}, lead={type=text}, url={type=keyword}}]",
"caused_by" : {
"type" : "mapper_parsing_exception",
"reason" : "Mapping definition for [_source] has unsupported parameters:  [properties : {image={type=keyword}, agency={type=keyword}, date_created={type=date}, title={type=text}, category={type=keyword}, content={type=text}, lead={type=text}, url={type=keyword}}]"
}
},
"status" : 400
}

之后,我还尝试使用以下PowerShell命令将我的文件索引到elasticsearch中:

Invoke-RestMethod "http://localhost:9200/main-news-test-data/doc/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "test.json"

但我再次从Powershell得到这个错误:

Invoke-RestMethod : {
"error" : {
"root_cause" : [
{
"type" : "json_e_o_f_exception",
"reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source:
(org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 1])n at
[Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 2, column: 1]"
}
],
"type" : "json_e_o_f_exception",
"reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source:
(org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 1])n at
[Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 2, column: 1]"
},
"status" : 400
}

那么我该怎么办呢?如何将JSON文件导入到可按字段查询的弹性搜索中?

根据我读到的内容,我可以说:

你的地图很奇怪刚放:

PUT /main-news-test-data
{
"mappings": {
"properties": {
"content": {
"type": "text"
},
"title": {
"type": "text"
},
"lead": {
"type": "text"
},
"agency": {
"type": "keyword"
},
"date_created": {
"type": "date"
},
"url": {
"type": "keyword"
},
"image": {
"type": "keyword"
},
"category": {
"type": "keyword"
}
}
}
}

你的Json错了。批量不使用有效的json。bulkapi的文件如下所示:

{ "index" : { "_index" : "main-news-test-data", "_id" : "1" } }
{ "field1" : "value1" }
{ "index" : { "_index" : "main-news-test-data", "_id" : "2" } }
{ "field1" : "value2" }

还请注意_分数":1.0,没有理由出现在您的请求中,并且该_type已被弃用(如果您使用7.0+,则_type只能是_doc,应被忽略(

最新更新