0

I would like to retrieve a nested object from documents in my index called "userprofiles".

My UserProfile model:

public class UserProfileModel

{
    public string FullName { get; set; }
    public string Oid { get; set; }
    public string Upn { get; set; }
    public List<SsoLink> FavoriteSsoLinks { get; set; } = new List<SsoLink>();
}

My SsoLink Model:

public class SsoLink
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Url { get; set; }
    public string Owner { get; set; }
}

Index creation:

PUT userprofiles
{
    "mappings" : {
        "properties" : {
            "FavoriteSsoLinks" : {
                "type" : "object"
            }
        }
    }
}

My Query:

var searchResponse = _client.Search<UserProfileModel>(s => s
                .Index(_profileIndex)
                .Query(q=>q
                    .Term(t => t.Field(t => t.Oid).Value(oid)
                        )
                    )
                );

Right now it returns the documents, but the favoritelinks object is blank, however I see objects listed from Kibana. I must be missing something obvious, but having trouble figuring this out.

Here is an example of my data:

enter image description here

6
  • 1
    Query appears to be correct. Can you add a sample document from your index Commented Apr 26, 2020 at 1:43
  • 1
    Query is fine, I tried at my end. Could be the case the documents which you are searching for oid might not be having favoriteSsoLinks value. You should run { "query": { "term": { "oid": { "value": "VALUE" } } } } and check value in kibana dev tools Commented Apr 26, 2020 at 2:59
  • Interesting, I am trying to find all the favoriteSsoLinks where oid = "someOID". How did you make your index? Commented Apr 26, 2020 at 3:06
  • I just created a sample sample document with object type and a text field and my returned model has the object field. In your case you can run the query in kibana dev tools to make sure "favoriteSsoLinks" has value(could be empty) or if you are using source filtering then you are mentioning this field Commented Apr 26, 2020 at 3:15
  • Ok, so when I search with dev tools GET userprofiles/_search { "query": { "term": { "_id": { "value": "1-123-1234-1232-41234-12341" } } } } I can see the response, but in my code I don't get them favoriteSsoLinks back... Commented Apr 26, 2020 at 3:32

1 Answer 1

1

Index creation example uses "FavoriteSsoLinks" as the property, but the Kibana screenshot uses "favoriteSsoLinks" starting with a lowercase f - which is correct? My suspicion is that property casing may be the issue, but would need to see the mapping in the index to know if this is correct.

The 7.x client is strict about property name casing in JSON, and by default uses camelcase property names to match to POCO property names. For example, by default

  • "favoriteSsoLinks" in JSON will be a match for FavoriteSsoLinks POCO property
  • "FavoriteSsoLinks" in JSON will not be a match for FavoriteSsoLinks POCO property

This behaviour can be changed with DefaultFieldNameInferrer(Func<string, string>) on ConnectionSettings for all properties, or on a property by property basis using attributes on properties such as DataMemberAttribute or PropertyNameAttribute, or using DefaultMappingFor<T> where T is the POCO type.

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.