# How are multiple types handled at ingestion?

**URL:** <https://discuss.elastic.co/t/how-are-multiple-types-handled-at-ingestion/58643>\
**Category:** Elasticsearch\
**Created:** [August 23, 2016, 5:29am UTC](https://discuss.elastic.co/t/how-are-multiple-types-handled-at-ingestion/58643 "2016-08-23T05:29:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![streamn](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@streamn](https://discuss.elastic.co/u/streamn)\
**Post date:** [August 23, 2016, 5:29am UTC](https://discuss.elastic.co/t/how-are-multiple-types-handled-at-ingestion/58643/1 "2016-08-23T05:29:21Z")

</div>

Hello,

I see that a `field` can have multiple `types`, but the documentation examples focus on `string` vs. `not analyzed` type of situation

I wonder if it's possible to have multiple types like:

- numbers as strings and number types:
- date as string and date types
- boolean as string and boolean types  
?

If so, how would that work?  
assuming the mapping is defined, would elasticsearch parse the single input into the multiple types? or do i need to parse the input and build an object with the various types ?  
Is there any kind of logstash plugin that does this?

Thanks

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [August 23, 2016, 8:43am UTC](https://discuss.elastic.co/t/how-are-multiple-types-handled-at-ingestion/58643/2 "2016-08-23T08:43:04Z")

</div>

The mapping definition allows you to interpret how the values in your JSON are mapped to entries in the search index. Normally a field called `foo` in your JSON is mapped to a field in your index called `foo` but you can include some additional interpretations in the `fields` section. Here's an example where we try coerce a JSON field called `foo` into an integer field called `foo.asInt`:

```
PUT /test
{
   "mappings": {
	  "doc": {
		 "properties": {
			"foo": {
			   "type": "keyword",
			   "fields": {
				  "asInt": {
					 "type": "integer",
					 "ignore_malformed": true
				  }
			   }
			}
		 }
	  }
   }
}
POST test/doc
{
	"foo":[1,2,"n/a"]
}
GET test/_search
{
	"query":{
		"match":{
			"foo.asInt":2
		}
	}
}
GET test/_search
{
	"query":{
		"match":{
			"foo":"n/a"
		}
	}
}

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![streamn](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@streamn](https://discuss.elastic.co/u/streamn)\
**Post date:** [August 23, 2016, 8:58am UTC](https://discuss.elastic.co/t/how-are-multiple-types-handled-at-ingestion/58643/3 "2016-08-23T08:58:17Z")

</div>

Thanks Mark

I see you use the type `keyword`  
is that the trick here?  
I also don't see this `keyword` feature in the docs of 2.3.  
Is this a 5.0 feature?

Thanks

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [August 23, 2016, 9:09am UTC](https://discuss.elastic.co/t/how-are-multiple-types-handled-at-ingestion/58643/4 "2016-08-23T09:09:53Z")

</div>

> [@streamn](#):
>
> I also don't see this keyword feature in the docs of 2.3. Is this a 5.0 feature?

Oops. Yes 🙂 It's essentially like a `string` with a `not_analyzed` setting.

> [@streamn](#):
>
> is that the trick here?

The `keyword` type in my example is not central to the question of how you define multiple types. I could have picked any types e.g. `string`, `integer` etc and organised them whatever way round I wanted. A convention that many use for example with strings is to have `foo` as primary field of type `string` and `analyzed` for search then to have an alternative `foo.raw` field mapped that is `not_analyzed` for use in analytics. Some have suggested that Kibana end users may be more inclined to pick field `foo` than `foo.raw` as the subject of a pie chart so it may make more sense to use a convention that reverses the configuration and have a `not_analyzed` foo field and an alternative mapping field named `foo.search` which is `analyzed`.  
Ultimately it's up to you though to pick a convention that works.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:25pm UTC](https://discuss.elastic.co/t/how-are-multiple-types-handled-at-ingestion/58643/5 "2017-07-05T22:25:57Z")

</div>


