# 【Elasticsearch】エラー failed to parse field \[host\] of type \[text\]

**URL:** <https://discuss.elastic.co/t/elasticsearch-failed-to-parse-field-host-of-type-text/201714>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [October 1, 2019, 2:49am UTC](https://discuss.elastic.co/t/elasticsearch-failed-to-parse-field-host-of-type-text/201714 "2019-10-01T02:49:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harue](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@harue](https://discuss.elastic.co/u/harue)\
**Post date:** [October 1, 2019, 2:49am UTC](https://discuss.elastic.co/t/elasticsearch-failed-to-parse-field-host-of-type-text/201714/1 "2019-10-01T02:49:44Z")

</div>

お世話になります。

現在Filebeat→Logstash→Elasticsearch(ingest node)の連携を行っています。

バージョン  
Filebeat：7.3  
Logstash：7.3  
Elasticsearch：7.3

Filebeatのinputログ  
_1286536308.779 180 192.168.0.224 TCP\_MISS/200 411 GET [http://liveupdate.symantecliveupdate.com/minitri.flg](http://liveupdate.symantecliveupdate.com/minitri.flg) - DIRECT/125.23.216.203 text/plain_

Logstashのconfig(filter句は空)

```
input {
  beats {
   port => XXXX
  }
}

filter {
   }

output{
   elasticsearch{
   hosts => ["XX.XXX.XXX.XXX:XXXX"]
   user => "XXXXX"
   password => "XXXX"
   pipeline => "squid_access"
   index => "squid_access"
   }
}

```

Elasticsearchのingest node

```
GET /_ingest/pipeline/squid_access

{
  "squid_access" : {
    "processors" : [
      {
        "grok" : {
          "field" : "message",
          "patterns" : [
            "%{NUMBER:timestamp}%{SPACE}%{NUMBER:duration} %{IP:client_address} %{WORD:cache_result}/%{POSINT:status_code} %{NUMBER:bytes} %{WORD:request_method} %{NOTSPACE:url} %{NOTSPACE:user} %{WORD:hierarchy_code}/%{NOTSPACE:server} %{NOTSPACE:content_type}"
          ]
        }
      }
    ]
  }
}

```

連携すると、Elasticsearchにてエラーが発生します。

Elasticsearch log  
`org.elasticsearch.index.mapper.MapperParsingException: failed to parse field [host] of type [text] in document with id '-XXXXXX'. Preview of field's value: '{hostname=XXXXX, os={kernel=3.10.0-957.27.2.el7.x86_64, codename=Core, name=CentOS Linux, family=redhat, version=7 (Core), platform=centos}, containerized=false, name=XXXXX, id=XXXXXXX, architecture=x86_64}'`

ご質問  
上記エラーの原因が分かりましたら教えてください。

気になることとして、Logstashの別のconfigにてpipelineの向き先を「squid\_access」にしたところエラーにはなりませんでした。  
今回のconfigとの差異はfilter句に処理を書いているか書いていないかです。そのためconfigのfilter句の記載に問題がありそうです。

---

<div class="post-metadata">

**Author:** ![tsgkdt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsgkdt/32/39151_2.png) [@tsgkdt](https://discuss.elastic.co/u/tsgkdt)\
**Post date:** [October 1, 2019, 5:54am UTC](https://discuss.elastic.co/t/elasticsearch-failed-to-parse-field-host-of-type-text/201714/2 "2019-10-01T05:54:11Z")

</div>

エラーは、textとして定義されている[host]というフィールドに、Preview of fieldsの後にあるようなオブジェクトを入れようとしているから、と見受けられます。

> GET /squid\_access/\_mapping

として、hostフィールドがどのように定義されているか確認してみてください。

```auto
    "mappings" : {
      "properties" : {
        "host" : {
          "type" : "text",
          }
        }
      }
    }

```

と、このようになっていたらsquid\_accessのマッピングが入れたいデータとあっていないということになろうかと思います。

同じエラーを起こす簡単な再現手順です。

```auto
# hostフィールドをtextで定義されるようにする
PUT hoge/_doc/1
{
  "host": "aiueo"
}

# textで定義されたフィールドにオブジェクトを入れる
PUT hoge/_doc/2
{
  "host" : {
    "hostname": "XXXXX",
    "os": {
      "kernel":"3.10.0-957.27.2.el7.x86_64", 
      "codename": "Core", 
      "name":"CentOS Linux",
      "family": "redhat", 
      "version":"7 (Core)",
      "platform": "centos"
      
    }, 
    "containerized": false,
    "name": "XXXXX",
    "id": "XXXXXXX",
    "architecture": "x86_64"
  }
}

```

表示されるエラー

```auto
 "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [host] of type [text] in document with id '2'. Preview of field's value: '{hostname=XXXXX, os={kernel=3.10.0-957.27.2.el7.x86_64, codename=Core, name=CentOS Linux, family=redhat, version=7 (Core), platform=centos}, containerized=false, name=XXXXX, id=XXXXXXX, architecture=x86_64}'"
      }
    ],

```

以上のことから、提示された情報からはlogstashのfilterの有無よりも、マッピング情報をまず確認したいです。

---

<div class="post-metadata">

**Author:** ![harue](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@harue](https://discuss.elastic.co/u/harue)\
**Post date:** [October 1, 2019, 7:52am UTC](https://discuss.elastic.co/t/elasticsearch-failed-to-parse-field-host-of-type-text/201714/3 "2019-10-01T07:52:09Z")

</div>

早急に回答頂きありがとうございます。

indexのマッピング情報を確認しました。  
おっしゃる通り、hostの型がtext型で定義されていました。

iindexを新規で作り直し、データとindexの型を合わせ実行したところエラーは解消されました。

大変助かりました。

---

<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 29, 2019, 7:52am UTC](https://discuss.elastic.co/t/elasticsearch-failed-to-parse-field-host-of-type-text/201714/4 "2019-10-29T07:52:13Z")

</div>

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