简体   繁体   中英

Dictionary field with name “Metadata”

This question stems from my previous post but i think it deserves separate thread.

In my document model i've created two fields of type Dictionary<string, object> :

public class Document 
{
    // some fields ....
    public Dictionary<string, object> Permissions { get; set; }
    public Dictionary<string, object> Metadata { get; set; }
}

I'm using default indexing policy (let elastic handle mapping).

private static void Main(string[] args)
{
    var settings = new ConnectionSettings(new Uri("http://127.0.0.1:9200"));
    settings.EnableDebugMode();
    settings.DefaultMappingFor<Document>(m => m
        .IndexName("documents")
    );
    var client = new ElasticClient(settings);

    foreach (var doc in SampleDocuments.Documents)
    {
        var result = client.IndexDocument(doc);

        Console.WriteLine($"Indexing {doc.Name}: {result.IsValid}");
    }
}

Now, looking at my documents from kibana i've noticed that only fields from Metadata field are mapped dynamically. Those from Permissions field are of unknown type .

Kibana 截图

Notice the icons on the left. Further investigation showed that changing Metadata field name to anything else (like Metadata1 ) disables auto detecting types (it is indexed in a same manner as Permissions ).

My question is: what is so special about that name? Secondary question is: how can I force elastic to index Permissions field in the same way as Metadata ? I've tried adding [Nested] and [Object] mapping, also setting max recursion level in AutoMap() but without success.

You simply need to refresh your index pattern in Stack Management > Index patterns > Refresh to make sure the latest mapping changes are picked up.

Also worth noting that as of 7.11.0, the refresh button has disappears as the index patterns are now refreshed automatically whenever needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM