# Force an object type into a text field?

**URL:** <https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609>\
**Category:** Elasticsearch\
**Created:** [February 6, 2018, 10:22am UTC](https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609 "2018-02-06T10:22:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheBronx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thebronx/32/18632_2.png) [@TheBronx](https://discuss.elastic.co/u/TheBronx)\
**Post date:** [February 6, 2018, 10:22am UTC](https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609/1 "2018-02-06T10:22:03Z")

</div>

I have a problem. We store http requests in elastic, and it turns out we are using the same parameter name in two different requests with different types.

Request A is sending a parameter named "operation" as a JSON object  
Request B is sending a parameter named "operation" as a string

If I set the "operation" field to type=text then request A fails to insert into elastic.  
If I set the "operation" field to an object then its B the one that fails.

Is there any way I can get both inserted into elastic? I don't need to search for that field, and I don't really care about the type. All I want is that information stored into elastic in some way.  
Is it possible?

Thanks!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 6, 2018, 10:26am UTC](https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609/2 "2018-02-06T10:26:50Z")

</div>

Might choosing to [not index the field at all](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/mapping-index.html) perhaps be an option?

---

<div class="post-metadata">

**Author:** ![TheBronx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thebronx/32/18632_2.png) [@TheBronx](https://discuss.elastic.co/u/TheBronx)\
**Post date:** [February 6, 2018, 10:33am UTC](https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609/3 "2018-02-06T10:33:35Z")

</div>

I have tried `"index": false` on that field, but still get an error.

It also seems that "ignore\_malformed" is not an option for "text" fields, which is weird cause a text field can fail too: `Can't get text on a START_OBJECT at 1:541`

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 6, 2018, 11:12am UTC](https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609/4 "2018-02-06T11:12:12Z")

</div>

Something like this may work:

```auto
PUT my_index 
{
  "mappings": {
    "doc": { 
      "properties": { 
        "name": { "type": "keyword" }, 
        "operation": { 
          "enabled": false,
          "type": "object"
        }
      }
    }
  }
}

PUT my_index/doc/1
{
    "name" : "Tom",
    "operation" : {
      "message" : "trying out Elasticsearch"
    }
}

PUT my_index/doc/2
{
    "name" : "Jerry",
    "operation" : "trying out Elasticsearch"
}

GET my_index/_search
{
  "query": {
    "match_all": {}
  }
}

```

---

<div class="post-metadata">

**Author:** ![TheBronx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thebronx/32/18632_2.png) [@TheBronx](https://discuss.elastic.co/u/TheBronx)\
**Post date:** [February 6, 2018, 11:27am UTC](https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609/5 "2018-02-06T11:27:14Z")

</div>

Thank you @Christian_Dahlqvist at least now both requests are indexed, instead of just one of them 😃

But I don't understand how it works haha. Following your example, the **doc/1** is inserted but without the operation field.  
The **doc/2** is inserted and I can see the operation field in kibana.

I expected it to work just the opposite, I mean, if the mapping says operation is type=object, why am I only seeing the string one?

It works, and it is perfect, I would just love to understand why is it working like this.

---

<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:** [March 6, 2018, 11:27am UTC](https://discuss.elastic.co/t/force-an-object-type-into-a-text-field/118609/6 "2018-03-06T11:27:40Z")

</div>

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