LoginSignup
0
0

More than 1 year has passed since last update.

Elasticsearch 6ではindex定義に'_type'が必要

Posted at

Elasticsearch 7以上の場合はindexのmapping定義の_types

環境

Docker環境で以下の時

  • Elasticsearch 6.8.20
  • kibana 6.8.20
  • PHP7
docker-compose.yml

version: '3'
services:
  # 省略...
  es:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.8.20
    environment:
        - discovery.type=single-node
        - cluster.name=docker-cluster
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
        - "9200:9200"
    volumes:
        - es-data:/usr/share/elasticsearch/data
  kibana:
    image: docker.elastic.co/kibana/kibana:6.8.20
    ports:
        - "5601:5601"
    environment:
      ELASTICSEARCH_HOSTS: http://es:9200

  # 省略...

volumes:
  es-data:

  # 省略...

問題

In Connection.php line 636:

  {"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Fail  
  ed: 1: type is missing;2: type is missing;3: type is missing;4: type is missing;5: type is miss  
  ing;6: type is missing;7: type is missing;8: type is missing;9: type is missing;10: type is mis  
  sing;11: type is missing;12: type is missing;13: type is missing;14: type is missing;15: type i  
  s missing;16: type is missing;17: type is missing;18: type is missing;19: type is missing;20: t  
  ype is missing;21: type is missing;22: type is missing;23: type is missing;24: type is missing;  
  25: type is missing;26: type is missing;27: type is missing;28: type is missing;29: type is mis  
  sing;30: type is missing;31: type is missing;32: type is missing;33: type is missing;34: type i  
  s missing;35: type is missing;36: type is missing;37: type is missing;38: type is missing;39: t  
  ype is missing;40: type is missing;41: type is missing;42: type is missing;43: type is missing;  
  44: type is missing;45: type is missing;46:

...

上記が出る

解決法

Elasticsearch 6以下では _typeの記述が必要なので下記のように書いておく。


// 一例です

    public function index(int $id): array
    {
        return [
            'index' => [
                '_index' => 'index_name',
                '_type' => 'index_type',
                '_id' => $id,
            ],
        ];
    }

補足

Elasticsearch 7以降ではタイプレスAPIとして_typeがデフォルトで_docに設定されるようなので、指定は不要。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0