# Can logstash get the type of field?

**URL:** <https://discuss.elastic.co/t/can-logstash-get-the-type-of-field/61326>\
**Category:** Logstash\
**Created:** [September 23, 2016, 3:16am UTC](https://discuss.elastic.co/t/can-logstash-get-the-type-of-field/61326 "2016-09-23T03:16:46Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![WangXiangUSTC](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@WangXiangUSTC](https://discuss.elastic.co/u/WangXiangUSTC)\
**Post date:** [September 23, 2016, 7:42am UTC](https://discuss.elastic.co/t/can-logstash-get-the-type-of-field/61326/3 "2016-09-23T07:42:53Z")

</div>

OK, below is the problem I met.

> [@How to save different type in one field?](https://discuss.elastic.co/t/how-to-save-different-type-in-one-field/61209):
>
> I send logs to logstash, and then output to elasticsearch. the log is json type.for example： some like this: {"time":"2015-09-22:08:11:22", request:{"url":"192.168.0.1/test","user":"xiang"}} and others maybe: {"time":"2015-09-22:08:11:22", request:{"url":"192.168.0.1/test","user":{"name":"xiang","age":20}}} In my logstash config file: filter { json { source =\> "message" } } so , after deal with the first log, the type of "user" will be string in elasticsearch, but when deal with the…

so, I want to get the type of the field. for example, there are two different type log but with same field:  
{"url":"192.168.0.1/test","user":"xiang"}}  
{"url":"192.168.0.1/test","user":{"name":"xiang","age":20}}

then I use filter{ { json { source =\> "message" } } in logstash.  
If the type of "user" is string , I save the value in field "user\_name", if not ,save the value in field "user".  
Do you have any suggest?

---

_[View the full topic](https://discuss.elastic.co/t/can-logstash-get-the-type-of-field/61326)._
