Search code examples
elasticsearchkibanaelasticsearch-query

"type": "keyword", is mentioned in Elastic search mapping but still giving the error of " fielddata=true"


As you can see below in the kibana mapping"type": "keyword", is already mentioned then why it is still giving me an error, while i run the seconnd code block?

StatusCodeError: [illegal_argument_exception] Fielddata is disabled on text fiel ds by default. Set fielddata=true on [time-stamp] 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.<

{
  "web": {
    "aliases": {},
    "mappings": {
      "event": {
        "properties": {
            "participant-id": {
                        "type": "text",
                        "fields": {
                          "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                          }
                        }
                      },
                    }        
                  }
                },

I am trying to run this code

          else if(req.query["participant-id"] !== undefined)
          {
            console.log('participant id');
            esClient.search({
            index:ESindex,

            body: {
              sort:[{"time-stamp":{"order":"desc"}}],
              size:req.query.count,
              query: {
                  match_phrase: { "participant-id":req.query["participant-id"] },

              }

              }
          },function (error, response,status) {
              if (error){
                console.log(error);
                return res.json({ message: 'error' });
              }
              else {
                  response.hits.hits.forEach(function(hit){
                   return resData.push(hit);
                })
              }
              return res.send(resData);

          });
          }

Solution

  • You are sorting on time-stamp field, and mapping which you shared doesn't have this field, I am assuming this is defined as text field, and if your mapping is generated dynamically, you will have .keyword for time-stamp, Hence try using time-stamp.keyword in your sort clause.