0

I am using https://github.com/basemkhirat/elasticsearch package.

In es.php file i have below indices

'indices' => [
        'media' => [
            'settings' => [
                'number_of_shards' => 2,
                'number_of_replicas' => 2,
                'analysis' => [
                    'filter' => [
                        'custom_english_stemmer' => [
                            'type' => "stemmer",
                            'name' => "english"
                        ],
                        "english_stop" => [
                            'type' => "stop",
                            'stopwords' => "_english_"
                        ]
                    ],
                    "analyzer" => [
                        'custom_lowercase_analyzer' => [
                            // 'type' => 'custom',
                            'tokenizer' => 'standard',
                            'filter' => [
                                'lowercase',
                                'english_stop',
                                "custom_english_stemmer"
                            ]
                        ]
                    ]
                ]
            ],
            'mappings' => [
                'properties' => [
                    'id' => [
                        'type' => 'long',
                        'index' => false,
                        'doc_values' => false,
                    ],
                    'title' => [
                        'type' => 'text',
                        "analyzer" => 'custom_lowercase_analyzer'
                    ]
                ]
            ]
        ]
    ]

Now when php artisan es:indices:create is executed settings is created but mapping fails with an error message.

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
  },
  "status": 400
}

enter image description here

How to fix this issue

Sharath
  • 2,348
  • 8
  • 45
  • 81

1 Answers1

1

You are providing type in your create index code, remove media type from your index, as types are deprecated, see the removal of types for more information.

Please note in Elasticsearch 7.X still you can do some workaround to have custom types by having include_type_name param but it's not preferred as types will be totally removed in upcoming Elasticsearch 8.X.

In order to use create your index with custom type like media(default is _doc mentioned in your screen-shot) in your case, you need to pass include_type_name=true to index creation, template, and mappings APIs as mentioned in this official ES blog

Amit
  • 30,756
  • 6
  • 57
  • 88
  • if i remove `media` then how do i create multiple indexes basically **media** was my index name – Sharath Apr 28 '20 at 18:40
  • removing `media` will give `Undefined index: settings` – Sharath Apr 28 '20 at 18:45
  • @Sharath, you can give index name in create index request as part of URL please see how to create index in ES 7.X which is your version https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html – Amit Apr 29 '20 at 05:59
  • @Sharath please see this index request where both setting and mapping mentioned https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#mappings please note index name is in URL and not in body – Amit Apr 29 '20 at 06:01
  • yes through api it works only this is that through php from the library which i am using is failing so wanted to about it... well i tried the same thing in kibana it works well.. – Sharath Apr 29 '20 at 14:28
  • @Sharath, sorry didn't get you – Amit Apr 29 '20 at 14:35
  • like what ever you see within `media` array in php code i.e., settings and mappings, trying to run this in kibana or through api will work.. same structure through php code fails with above error – Sharath Apr 29 '20 at 17:24