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.

Id property inference

See original GitHub issue

Referring to this page: http://nest.azurewebsites.net/nest/index-type-inference.html

You can control which propery holds the Id:

[ElasticType(IdProperty="CrazyGuid")]
public class Car 
{
    public Guid CrazyGuidId { get; set; }
}

This will cause the the id inferring to happen on CrazyGuid instead of Id.

Is the mismatch deliberate or is this just a typo: should the attribute refer to CrazyGuidId, or should the property name be CrazyGuid? There are other typos on the page so it’s hard to tell ¯_(ツ)_/¯

I am having trouble getting the ID from items in ES using this method, using v1.4.2


EDIT: I came across this line on the same page:

Whenever an object is passed that needs to specify an id (i.e index, bulk operations) the object is inspected to see if it has an Id property and if so, that value will be used.

So the ID property only inferred from the type when using a .Id() search descriptor? If so, what’s the recommended way of getting the _id property for documents from the Search<T> api?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
russcamcommented, Jan 27, 2016

Upon further discussion on this issue, we’ve decided to keep the current implementation for the time being. We feel it would be potentially confusing if the Id property on the Poco were populated with data that is not contained within the _source field in Elasticsearch; A Poco instance is a representation of the source document.

I’ll add documentation for NEST 2.x demonstrating how to retrieve the _id from the metadata using the .Hits property on the response and set a property on the Source as demonstrated above.

2reactions
rikkitcommented, Jan 6, 2016

The uid property doesn’t exist in my mapping, imo it shouldn’t because it is already part of the document metadata. To reiterate my point, I expected this feature to be a “transparent” way to get the ID of a document without having to have an id field stored in the document metadata.

As it stands, this feature is not useful for me, exactly because the read case differs from the write case.

If I put this document into ES using this mechanism:

[ElasticType(IdProperty="Uid")]
class Poco {
    [JsonIgnore] // alternatively to this attribute mapping could be explicit and dynamic mapping disabled
    public string Uid {get;set;}
    public string Prop {get;set;}
}

_nest.Index<Poco>(x => x.Index(i).Type(t).Document(new Poco{ Uid = "banana", Prop = "apple" });

And then I retrieved it again:

var poco2 = _nest.Get<Poco>(x => x.Index(i).Type(t).Id("banana");

I would not have the same object (poco1.Uid == banana, poco2.Uid == null).

What use cases does the current behaviour serve? It’s not what I expected based on the documentation. And like @irfansharif says the workaround I posted is not easily testable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ids inference | Elasticsearch.Net and NEST
Here we instruct NEST to infer the Id for MyDTO based on its Name property. WithConnectionSettings(x => x .InferMappingFor<MyDTO>(m => m .IdProperty(p =>...
Read more >
Ids inference | Elasticsearch .NET Clients [7.17]
Another way to control Id inference is to mark the type with an ElasticsearchType attribute, setting IdProperty to the name of the property...
Read more >
[1904.13215] Property Inference for Deep Neural Networks
We propose to extract patterns based on neuron decisions as preconditions that imply certain desirable output property e.g., the prediction ...
Read more >
Property Inference for Deep Neural Networks
In this work, we infer properties corresponding to decision patterns of neurons in the DNN. Such patterns prescribe which neurons are on or...
Read more >
Property Inference Attacks Against t-SNE Plots
This paper shows how to perform perform privacy attacks against t-SNE plots. The reviewers were positive on the identification of the attack ...
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