VisualStudio using .Nest with hierarchy


(Sergi) #1

Hi all!!

First of all, sorry if this topic is an wrong thread.

I am using the nest to update or get the documents in ElasticSearch, but now I have a problem and I don't know if is possible solved it

I have these classes:

public class Archive : IElasticResult
{

	public string CodeDocument { get; set; }
	public string TypeDocument { get; set; }
	

	public Archive()
	{
		CodeDocument = "1";
		TypeDocument = string.Empty;
	}


}


public class WorkerArchive : Archive
{

	public string CodeWorker { get; set; }
	
	public WorkerArchive(string code)
	{
		CodeDocument = code;
		CodeWorker = "prove";
	}
	

}

If I create a new object WorkerArchive and update the register works:

var response2 = Elastic.Update(DocumentPath
.Id(a.CodeDocument),
u => u
.Index(IndexName)
.Type("archive")
.DocAsUpsert(true)
.Doc((Archive)a));

			}

The problem is when I want obtain this document, because I'm declaring the specific class:

ISearchResponse result = Elastic.Search(searchRequest);

And the return is of the type Archive, when have the structure of WorkerArchive.

Is possible have a list of hits of differents types?

Thanks for all!


(Russ Cam) #2

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.