Crud opearation is not working in Elasticsearch nest 5.0

public class Animal
public const string SearchIndex = "animals";
public int Id { get; set; }
public string AnimalType { get; set; }
public string TypeSpecificForAnimalType { get; set; }
public string Description { get; set; }
public string Gender { get; set; }
public string LastLocation { get; set; }

private void ValidateIfIdIsAlreadyUsedForIndex(string id)
		var idsList = new List<string> { id };
		var result = _elasticsearchClient.Search<Animal>(s => s
			.Query(p => p.Ids(idsList)));
		if (result.Documents.Any()) throw new ArgumentException("Id already exists in store");

I am using nest version and error i am getting
cannot convert from 'System.Collections.Generic.List' to 'System.Func<Nest.IdsQueryDescriptor,Nest.IIdsQuery>'

That's because the .Ids method takes a lambda function instead of just a list of ids. You can get the same behaviour by calling:

.Query(p => p.Ids(ids => ids.Values(id)))

Note that .Values takes a params string[], so you don't need idsList, you can just pass your one id parameter straight in.

Thanks , But this previous code is working in nest

The API for NEST must have changed at some point. There were big changes between 1.x and 2.x so it might have been around then. I haven't really used ids queries so I'm not sure :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.