Enabling File Data while using _bulk API


(Atul Harsha) #1

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


(David Pilato) #2

Please format your code using </> icon as explained in this guide. 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?

GET /cars/_mapping

(Atul Harsha) #3
    {
  "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


(David Pilato) #4

Then run the aggregation on color.keyword instead.

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

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

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


(Atul Harsha) #5

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


(David Pilato) #6

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


(Atul Harsha) #7

Thanks David for resolving my query. :smiley:


(system) #8

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