34

I'm trying to convert a project to use the latest Elasticsearch 6 and am having this problem. I don't know if the problem is "Product" vs "product". In my mappings and attributes I specify "products", so I am not sure why I get this error when I try to index a product.

Error:

Invalid NEST response built from a unsuccessful low level call on PUT: /products/products/1?pretty=true&error_trace=true

"Rejecting mapping update to [products] as the final mapping would have more than 1 type: [Product, products]"

Request:

{
  "id": 1,
  "warehouseId": 0,
  "productStatus": 1,
  "sku": "102377",
  "name": "Name",
  "shortDescription": "Description",
  "longDescription": "Description",
  "price": 37.3200
}

My code:

    [ElasticsearchType(Name = "products")]
    public class Product : BaseEntity
    {
        [Key]
        public int Id { get; set; }
        public int WarehouseId { get; set; }
        [Display(Name = "Product Status")]
        public Enums.ProductStatus ProductStatus { get; set; }
        [Required, StringLength(10)]
        public string Sku { get; set; }
        [Required, StringLength(200)]
        public string Name { get; set; }
        [StringLength(500), Display(Name = "Short Description")]
        public string ShortDescription { get; set; }
        [DataType(DataType.MultilineText), Display(Name = "Long Description")]
        public string LongDescription { get; set; }
        [Column(TypeName ="Money")]            
        public Nullable<decimal> Price { get; set; }
    }

connection.DefaultMappingFor<Product>(m => m.IndexName("products"));
Primico
  • 2,143
  • 3
  • 24
  • 36
  • Possible duplicate of [Can't create two Types to same index elasticsearch & Kibana](https://stackoverflow.com/questions/47632846/cant-create-two-types-to-same-index-elasticsearch-kibana) – Cavaz Aug 07 '18 at 13:19

7 Answers7

29

This is because of a breaking change in ES 6.x: mapping types were removed (even if for backward compatibility you can still specify it in the path) thus de facto limiting the index to a single type.

See here for more info.

Cavaz
  • 2,996
  • 24
  • 38
  • 2
    I am trying to migrate from ES 5 to 7, and it confuses me that some say mappings are removed, since they still talk about mappings in the docs for version 7: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/mapping.html – Jette Nov 10 '20 at 08:40
  • **mapping types** were removed. Before ES6 you could define more than one mapping type in the same index (say, `user` and `order`). Starting from ES6, indexes were constrained to a single mapping (so we still have a _mapping_), making the concept of _type_ redundant. See the doc [removal of mapping types](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html) for the reason behind this update – Cavaz Nov 10 '20 at 09:53
  • 1
    Thanks Cavaz... It confused me that you wrote "mappings were removed"... I guess it should have been "mapping types were removed". – Jette Nov 10 '20 at 10:26
6

Prior to elasticsearch v6, an index can have only 1 mapping by default. In previous version 5.x, multiple mapping was possible for an index. Though you may change this default setting by updating index setting "index.mapping.single_type": false .

In your case, my assumption is you had already created the index with mapping Product. That is why it was rejecting new mapping in your second request with "product" (p in small case).

1

I deleted the index and recreated it and it appears to be fine now. I think when I first created the index I didn't have the correct attribute name so that might explain the error I was getting.

Primico
  • 2,143
  • 3
  • 24
  • 36
1

In my case I was trying to delete a record following the official docs and I blindly put the _doc in the URL which led to this error.

This should be the mapping that you see under the Indices tab against Mappings section in the AWS console. changing the value in the URL solved it for me.

Hope this was helpful :)

Karan Sharma
  • 473
  • 5
  • 8
0

As Batsu says, from version 5 of elasticSearch onwards, the concept of treating the index as the database and the type as a table was removed to implement a lucene optimization.

The solution is to use an index by @Document.

Referral: https://www.elastic.co/guide/en/elasticsearch/reference/6.7/removal-of-types.html

Manuel Larrota
  • 391
  • 4
  • 6
0

My problem was in ES 6.8 for which I was using the PHP ElasticSearch client to send requests. My index was already using a single type but the type name was not the default _doc that was suggested/expected. In addition I was not adding the "type" parameter in the request to specify what the type was. My code:

$this->client->delete([
   "index" => 'myIndexName',
   "id" => $idToDelete
])

This resulted in the client adding a default type which was _doc which in my case was incorrect. Adding an explicit type in the request fixed the issue like below:

$this->client->delete([
   "index" => 'myIndexName',
   'type' => 'myTypeName',
   "id" => $idToDelete
])
apokryfos
  • 38,771
  • 9
  • 70
  • 114
0

As there would be a type for index , use below method to create mapping so that it maps with its type

client.indices.putMapping({
                index: indexName,
                include_type_name:true,
                type: type,
                body: mappingBody,
            })
            .then(async function (response: any) {
                console.log('response', response);
                return response;
            })
            .catch(function (error: any) {
                console.log('error', error);
                throw error;
            });
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 27 '22 at 07:48