Elasticsearch cannot parse the string value in json?

Failure when writing some json data to es with logstash.

{"type"=>"mapper_parsing_exception", "reason"=>"object mapping for [Data.responsedto] tried to parse field [responsedto] as object, but found a concrete value"}

json data

{
	"SourceType": "ScmLog",
	"LogLevel": "info",
	"ApiName": "trade_push.php",
	"ApiUrl": "http://xxx.xx.cn/openapi2/trade_push.php",
	"Token": "",
	"Data": {
		"requestdto": [{
			"tid": "xxxxx-1",
			"trade_status": 30,
			"pay_status": 2,
			"delivery_term": 1,
			"trade_time": "2021-05-12T15:04:59",
			"pay_time": "2021-05-12T15:05:06",
			"fenxiao_type": null,
			"purchase_id": 0,
			"fenxiao_nick": null,
			"buyer_nick": "XXX",
			"buyer_email": null,
			"pay_id": "xxxxxx",
			"pay_account": null,
			"receiver_name": "xxx",
			"receiver_province": "xxxx",
			"receiver_city": "xxxx",
			"receiver_district": "xxx",
			"receiver_address": "xxxxx",
			"receiver_mobile": "xxxxxx",
			"receiver_telno": null,
			"receiver_zip": null,
			"logistics_type": null,
			"invoice_kind": null,
			"invoice_title": null,
			"invoice_content": null,
			"remark_flag": null,
			"buyer_message": "",
			"seller_memo": null,
			"seller_flag": null,
			"post_amount": null,
			"cod_amount": 0,
			"ext_cod_fee": 0,
			"other_amount": 0,
			"paid": 0.0,
			"id_card_type": null,
			"id_card": null,
			"is_auto_wms": null,
			"wms_type": null,
			"warehouse_no": null,
			"order_list": [{
				"oid": "xxxxxxxxxxx",
				"num": 0,
				"price": 0.0,
				"status": null,
				"refund_status": 2,
				"goods_id": "303",
				"spec_id": "303",
				"goods_no": null,
				"spec_no": "8010020014",
				"goods_name": "xxxx",
				"spec_name": "xxxxx",
				"adjust_amount": 0,
				"discount": null,
				"paid": 0.0,
				"share_discount": 0,
				"cid": 0,
				"remark": null
			}]
		}],
		"responsedto": "{\"code\":0,\"message\":\"\",\"error_count\":0,\"new_count\":0,\"chg_count\":1}"
	}
}

Is there any way to parse the string value in "responsedto"?

I'm moving your question to #elastic-stack:logstash as you will have probably to add some filters to extract the json from the string Data.responsedto.

The other solution, but it depends on what you are trying to do, is to change the mapping for elasticsearch and make Data.responsedto as a text field.
Or just ignore completely its content but just store it in the source.

What are you trying to achieve here with that field?

I only need "Data.responsedto" to be written into es.

So change the mapping and set this field to text. And set index to false on this field as it won't make any sense IMO to index it.

Even better, set it to "enabled": false. See the example in enabled | Elasticsearch Guide [7.12] | Elastic

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.