"type": "keyword", 在Elastic search mapping 中有提到,但仍然报“fielddata=true”的错误

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

正如您在下面的 kibana 映射中看到的那样"type": "keyword", 已经提到了那么为什么它仍然给我一个错误,而我 运行 第二个代码块?

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
                          }
                        }
                      },
                    }        
                  }
                },

我正在尝试 运行 此代码

          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);

          });
          }

您在 time-stamp 字段上排序,而您共享的映射没有这个 field,我假设它被定义为 text 字段,如果您的映射是动态生成的,您将有 .keyword for time-stamp,因此请尝试在您的排序子句中使用 time-stamp.keyword