映射ElasticSearch Apache模块字段

问题描述

我是ES的新手,我正面临着一个小问题。

我将metricbeat Apache模块与ES集成在一起,并且工作正常。

问题是metricbeat Apache模块报告apache的Web流量KB(字段apache.status.total_kbytes),而不是我想创建自己的字段,其名称为“ apache.status.total_mbytes)

我正在尝试使用followind api命令通过Dev Console创建新的映射:

PUT /metricbeat-7.2.0/_mapping
{
  "settings":{

  },"mappings" : {
      "apache.status.total_mbytes" : {
        "full_name" : "apache.status.total_mbytes","mapping" : {
          "total_mbytes" : {
            "type" : "long"
          }
        }
      }
    }
}

静止ES返回以下错误

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception","reason" : "Root mapping deFinition has unsupported parameters:  [settings : {}] [mappings : {apache.status.total_mbytes={mapping={total_mbytes={type=long}},full_name=apache.status.total_mbytes}}]"
      }
    ],"type" : "mapper_parsing_exception",full_name=apache.status.total_mbytes}}]"
  },"status" : 400
}

仅供参考

以下内容可能会有所启发

GET /metricbeat-*/_mapping/field/apache.status.total_kbytes

返回

{
  "metricbeat-7.9.2-2020.10.06-000001" : {
    "mappings" : {
      "apache.status.total_kbytes" : {
        "full_name" : "apache.status.total_kbytes","mapping" : {
          "total_kbytes" : {
            "type" : "long"
          }
        }
      }
    }
  },"metricbeat-7.2.0-2020.10.05-000001" : {
    "mappings" : {
      "apache.status.total_kbytes" : {
        "full_name" : "apache.status.total_kbytes","mapping" : {
          "total_kbytes" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

我想念什么? _mapping命令是否错误

预先感谢

解决方法

一个工作示例:

创建新索引

PUT /metricbeat-7.2.0
{
  "settings": {},"mappings": {
    "properties": {
      "apache.status.total_kbytes": {
          "type": "long"
        }
    }
  }
}

然后GET metricbeat-7.2.0/_mapping/field/apache.status.total_kbytes将导致(与您的示例相同):

{
  "metricbeat-7.2.0" : {
    "mappings" : {
      "apache.status.total_kbytes" : {
        "full_name" : "apache.status.total_kbytes","mapping" : {
          "total_kbytes" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

现在,如果您要将新字段添加到现有映射中,请按以下方式使用API​​:

更新现有索引

PUT /metricbeat-7.2.0/_mapping
{
  "properties": {
    "total_mbytes": {
      "type": "long"
    }
  }
}

然后GET metricbeat-7.2.0/_mapping将为您显示更新的映射:

{
 "metricbeat-7.2.0" : {
    "mappings" : {
      "properties" : {
        "apache" : {
          "properties" : {
            "status" : {
              "properties" : {
                "total_kbytes" : {
                  "type" : "long"
                }
              }
            }
          }
        },"total_mbytes" : {
          "type" : "long"
        }
      }
    }
  }
}

另外,看看Put Mapping Api