question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested attribute on List<string> generating unwanted properties

See original GitHub issue

NEST/Elasticsearch.Net version: 2.3.3

Elasticsearch version: 2.3.2

Description of the problem including expected versus actual behavior:

I have a mapping for a list<string> set with the Nested attribute and it’s creating unwanted properties on the ES mapping.

[Nested(IncludeInParent=true)]
public List<String> raw_amenities { get; set; }

yields

raw_amenities": {
     "type": "nested",
     "include_in_parent": true,
     "properties": {
          "chars": {
               "type": "string"
           },
           "length": {
               "type": "integer"
            }
      }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
russcamcommented, Sep 2, 2016

Just to follow up on what @gmarz has said, you would want to map it as a string type

[String]
public List<String> raw_amenities { get; set; }

in fact, if you don’t need to set any other properties for the type e.g. a different analyzer, not analyzed, etc. then you don’t even need the attribute applied, just calling AutoMap() will infer a string type mapping for List<string>. With Elasticsearch mappings, there is no distinction between a single property type and a collection property type i.e.

public class Household
{
    public string Amenity { get; set; }
    public List<string> Amenities { get; set; } 
}

Both Amenity and Amenities would be mapped as string data type in Elasticsearch.

Now, if you were dealing with say a List<Amenity> where Amenity type was

public class Amenity
{
    public string Name { get; set; }
    public DateTimeOffset Added { get; set; }
}

then the default inferred mapping for this would be object. This is fine for some scenarios, but with object mapping, the association between Name and Added for a given Amenity instance is not stored in the inverted index. For example, imagine the following amenities are indexed for a Household document

var household = new Household 
{
    Id = 1,
    Amenities = new List<Amenity>
    {
        new Amenity { Name = "electricity", Added = new DateTime(2016, 1, 1) },
        new Amenity { Name = "gas", Added = new DateTime(2016, 1, 8) },
    }
}

client.Index(household);

if Amenities is mapped as an object type, a search for Name="electricity" and Added=new DateTime(2016, 1, 8) would return the document as a match. If Amenities is mapped as a nested type however, the document would not be a match.

I hope that helps explain the difference.

0reactions
Mpdreamzcommented, Sep 13, 2016

Closing this before we attempt something too clever 😄 we’d have to unpack PropertyType see if its IEnumerable<T> then check if T is a reference type all for a small gain.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript: Omit nested property
3 Answers. First, Omit attributeValues , then add it back with properties removed.
Read more >
How to include nested properties is featuredProperties?
To work around this, first create a top-level property for the state and add it as a featured property: let PersonSchema = coda.makeObjectSchema ......
Read more >
Work with nested attributes - AWS SDK for Java 2.x
Work with nested attributes. A nested attribute in DynamoDB is embedded in another attribute. Examples are list elements and map entries.
Read more >
Csvhelper nested objects. Ignore() on the nested property, bu
Csvhelper nested objects. Ignore() on the nested property, but I think this is not expected behavior. Generic. Nested object initializers elegantly solve ...
Read more >
Lists and Tuples in Python
Lists can contain any arbitrary objects. List elements can be accessed by index. Lists can be nested to arbitrary depth. Lists are mutable....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found