Nest, Routing_missing_exception

Hi,

We want to implement elastic search in our application and are now in a bit of the research phase.
We first played around a bit with the dev-tools of Kibana, and we could index different documents with routing.

We now want to do the same thing using the NEST package. (We are currently using Dotnet core 3.1 and NEST 7.12.1)

I enabled routing when creating the index mappings, but when we try to index a document, we get following error:

image

On startup we add default mappings

    private static void AddDefaultMappings(ConnectionSettings settings)
        {
            settings
            .DefaultMappingFor<CommentDTO>(m => m
                    .Ignore(c => c.RowVersion)
                    .IndexName("comments")
                    //.DisableIdInference(true)
                    //.RoutingProperty(c => c.Routing)
                );
        }

and create the index, telling it that routing is required.

    private static void CreateIndexes(IElasticClient client)
        {
            var createIndexResponse = client.Indices.Create("comments",
                index => index.Map<CommentDTO>(x => x
                    .AutoMap()
                    .RoutingField(r => r.Required())
                )
            );
        }

If I check the mappings with Kibana these look correct
(I know, not the best code, what if indexes already exist and etc... I always remove the created index to start clean. For now we just want something that works, so we are confident moving forward)

From our application we are trying to index an object of the type "CommentDTO" using the following line of code

`var result = await elasticClient.IndexDocumentAsync(comment); `

If we don't enable routing, this works, and we can find the document with Kibana. But once I enable Routing, I get the error response back from elastic search.

The only documentation I found about routing with Nest was the one about routing inference

Wich is basicly saying that Nest will automatically search for the parameter "Routing" in my object with reflection, or I can specify a different one by setting one in the default mapping for that object.
To test this I added the property "Routing" to my object with a default value like this.

    public class CommentDTO
    {
        ...
        public Guid Routing { get; set; } = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E");
    }

Still not working.

We have been stuck on this for a while now and hope somebody will be able to help us.

Already a big thanks in advance

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