0

I am trying to create an index for my project to elasticsearch.

following are my classes

public class Asset
{
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; }
    public AssetComponent Component { get; set; }
    public AssetSite Site { get; set; }
    public AssetComposition AssetComposition { get; set; }
    public string SerialNumber { get; set; }
    public string WorkOrderNumber { get; set; }
    public AssetFigure Figure {get;set;}
    public string SkuNumber { get; set; }
    public Status AssetStatus { get; set; }
    public Status InspectionStatus { get; set; }
    public BsonDocument UserDefinedAttributes { get; set; }
    public TimeAndUserTrail Trail { get; set; }
    [BsonIgnoreIfDefault]
    public List<Identifier> Identifiers { get; set; } = new List<Identifier>();
    [BsonIgnoreIfDefault]
    public List<Document> Documents { get; set; } = new List<Document>();
    public Status OrderStatus { get; set; }
}

public class AssetComponent
{
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; }
    public string Name { get; set; }
}

public class AssetSite
{
    [BsonRepresentation(BsonType.ObjectId)]
    public string LocationId { get; set; }
    [BsonRepresentation(BsonType.ObjectId)]
    public string SiteId { get; set; }
}

public class AssetComposition
{
    public List<AssetComponentComposition> SubAssemblies { get; set; }
    public List<AssetComponentComposition> Parts { get; set; }
    public List<AssetComponentComposition> Accessories { get; set; }
}

public class AssetComponentComposition
{
    public string Name { get; set; }
    public string AssetType { get; set; }
    public List<ObjectId> AssetIds { get; set; }
}

public class AssetFigure
{
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; }
    public string Name { get; set; }
}

public class Status
{
    public string Id { get; set; }
    public string Value { get; set; }
}

And in elasticsearch create index method

var createIndexResponse = client.CreateIndex(indexName, c => c
            .Mappings(ms => ms
                .Map<Asset>(m => m
                    .AutoMap<AssetComposition>()
                    .AutoMap<AssetComponent>()
                    .AutoMap<AssetSite>()
                    .AutoMap<AssetFigure>()
                    .AutoMap<BsonDocument>()
                    .AutoMap<TimeAndUserTrail>()
                    .AutoMap<Core.Entities.Status>()
                    .AutoMap(typeof(AssetComponentComposition))
                    .AutoMap(typeof(Identifier))
                    .AutoMap(typeof(Document))
                    .AutoMap(typeof(ObjectId))
                )
            )
        );

When I run this, I am getting the following exception. System.Reflection.AmbiguousMatchException: 'Ambiguous match found.' I tried to resolve this using the following link from elasticsearch official document https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/auto-map.html

But again I didn't resolved the issue. Please help.

5
  • Can you test by commenting some lane and tell us witch field(s) throw the exception? Commented Feb 13, 2019 at 11:46
  • Exception throws in .map command Commented Feb 13, 2019 at 11:51
  • yeah but can you remove some field from Asset Class in order to target witch one is the problem (test ObjectId first ;)) ? Commented Feb 13, 2019 at 11:55
  • It looks BsonDocument is the problem Commented Feb 13, 2019 at 12:55
  • Yeah, you have to map manually your class then. You are lucky you got not many fields :). Commented Feb 13, 2019 at 13:44

1 Answer 1

1

The problem is occurring due to the 'BsonDocument' which has inbuilt properties which need to be map to the elastic search mapping environment. After adding those additional fields the issue resolved

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.