# Enabling File Data while using \_bulk API

**URL:** <https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023>\
**Category:** Elasticsearch\
**Created:** [September 27, 2017, 7:59pm UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023 "2017-09-27T19:59:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atul\_Harsha](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@Atul\_Harsha](https://discuss.elastic.co/u/Atul_Harsha)\
**Post date:** [September 27, 2017, 7:59pm UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/1 "2017-09-27T19:59:47Z")

</div>

Hi all,  
I am elastic search beginner and i am stuck in the following code. Please Help me out  
POST /cars/transactions/\_bulk  
{ "index": {}}  
{ "price" : 10000, "color" : "red", "make" : "honda", "sold" : "2014-10-28" }  
{ "index": {}}  
{ "price" : 20000, "color" : "red", "make" : "honda", "sold" : "2014-11-05" }  
{ "index": {}}  
{ "price" : 30000, "color" : "green", "make" : "ford", "sold" : "2014-05-18" }  
{ "index": {}}  
{ "price" : 15000, "color" : "blue", "make" : "toyota", "sold" : "2014-07-02" }  
{ "index": {}}  
{ "price" : 12000, "color" : "green", "make" : "toyota", "sold" : "2014-08-19" }  
{ "index": {}}  
{ "price" : 20000, "color" : "red", "make" : "honda", "sold" : "2014-11-05" }  
{ "index": {}}  
{ "price" : 80000, "color" : "red", "make" : "bmw", "sold" : "2014-01-01" }  
{ "index": {}}  
{ "price" : 25000, "color" : "blue", "make" : "ford", "sold" : "2014-02-12" }

```
GET /cars/transactions/_search
{
    "size" : 0,
    "aggs" : { 
        "popular_colors" : { 
            "terms" : { 
              "field" : "color"
            }
        }
    }
}

```

While using the above code I get the following error:  
"error": {  
"root\_cause": [  
{  
"type": "illegal\_argument\_exception",  
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [color] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."

Please tell me how to fix this

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 27, 2017, 9:43pm UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/2 "2017-09-27T21:43:27Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

You need to change the mapping I guess. What is your mapping look like?

```auto
GET /cars/_mapping

```

---

<div class="post-metadata">

**Author:** ![Atul\_Harsha](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@Atul\_Harsha](https://discuss.elastic.co/u/Atul_Harsha)\
**Post date:** [September 29, 2017, 5:27am UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/3 "2017-09-29T05:27:58Z")

</div>

> [@dadoonet](#):
>
> GET /cars/\_mapping

```
    {
  "cars": {
    "mappings": {
      "transactions": {
        "properties": {
          "color": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "fielddata": {
            "type": "boolean"
          },
          "make": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "price": {
            "type": "long"
          },
          "sold": {
            "type": "date"
          }
        }
      }
    }
  }
}

```

This is the result generated with GET /cars/\_mapping

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 29, 2017, 7:29am UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/4 "2017-09-29T07:29:18Z")

</div>

Then run the aggregation on `color.keyword` instead.

BTW I suspect you did something wrong when I see this line:

```auto
          "fielddata": {
            "type": "boolean"
          },

```

You probably tried to push a document although you wanted to update the mapping.

---

<div class="post-metadata">

**Author:** ![Atul\_Harsha](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@Atul\_Harsha](https://discuss.elastic.co/u/Atul_Harsha)\
**Post date:** [September 29, 2017, 10:08am UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/5 "2017-09-29T10:08:26Z")

</div>

Thankyou David using color.keyword worked in this case. But can you please tell me why are we using color.keyword instead of color. This would help me in future

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 29, 2017, 11:33am UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/6 "2017-09-29T11:33:30Z")

</div>

To run aggregations you need to use a `keyword` type field. Read [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/keyword.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/keyword.html)

---

<div class="post-metadata">

**Author:** ![Atul\_Harsha](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@Atul\_Harsha](https://discuss.elastic.co/u/Atul_Harsha)\
**Post date:** [September 29, 2017, 11:56am UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/7 "2017-09-29T11:56:24Z")

</div>

Thanks David for resolving my query. 😃

---

<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:** [October 27, 2017, 11:56am UTC](https://discuss.elastic.co/t/enabling-file-data-while-using-bulk-api/102023/8 "2017-10-27T11:56:52Z")

</div>

Closed on October 27, 2017, 11:56am UTC

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