Dev
Dev

Reputation: 172

Keyword mapping for sub document in elastic NEST

I learn now Nest 6.x client for elasticsearch I want to use term search in sub documents. I have this classes:

public class BaseTest
    {
        public string Id { get; set; }

        public SubBase SubDocument { get; set; }

        public Guid TypeId { get; set; }

        public string BaseTitel { get; set; }
    }
public class SubBase
    {
        public int Id { get; set; }
        public Guid IdGuid { get; set; }
        public string Titel { get; set; }
    }

and use this mapping to create an index:

.Mappings(mp => mp
                    .Map<BaseTest>(m => m
                        .Properties(pr => pr
                            .Keyword(kw => kw
                                .Name(nm => nm.BaseTitel)))
                        .Properties(pr => pr
                            .Keyword(kw => kw
                                .Name(nm => nm.TypeId)))
                        .Properties(pr => pr
                            .Keyword(kw => kw
                                .Name(nm => nm.SubDocument.Titel)))
                        .Properties(pr => pr
                            .Keyword(kw => kw
                                .Name(nm => nm.SubDocument.IdGuid)
                            ))))

wenn I try to search GUID(or string in GUID format, weil I save SubBase.Titel as Guid for tests) values in BaseTest it works, but not in SubBase. To search I use this query:

.Query(q => q
 .ConstantScore(cs => cs
  .Filter(f => f
   .Term(t => t
    .SubDocument.Titel, "5d511b8a-37c7-40c1-a5c3-4de13e16e379"))))

Update
New mapping:

.Mappings(mp => mp
                    .Map<BaseTest>(m => m
                        .Properties(pr => pr
                            .Keyword(kw => kw
                                .Name(nm => nm.BaseTitel)
                                .Name(nm => nm.TypeId)
                            )
                            .Object<SubBase>(o => o
                                .Name(n => n.SubDocument)
                                .Properties(p => p
                                    .Keyword(k => k
                                        .Name(n => n.Titel)
                                        .Name(n => n.IdGuid)))))))

Now I can find Guid properties, but not a propery with type string an value like "5d511b8a-37c7-40c1-a5c3-4de13e16e379"

Upvotes: 0

Views: 362

Answers (1)

Dev
Dev

Reputation: 172

Thanks Russ Cam

.Mappings(mp => mp
               .Map<BaseTest>(m => m
                 .Properties(pr => pr
                   .Keyword(kw => kw
                     .Name(nm => nm.BaseTitel))
                   .Keyword(kw => kw
                     .Name(nm => nm.TypeId))
                   .Object<SubBase>(o => o
                     .Name(n => n.SubDocument)
                       .Properties(p => p
                         .Keyword(k => k
                           .Name(n => n.Titel))
                         .Keyword(k => k
                           .Name(n => n.IdGuid)))))))

Upvotes: 0

Related Questions