Parse query to NEST(.net client for elasticsearch)


(Bien Tran) #1

I'm trying to parse this query to NEST but no luck.

{
"query" : {
"filtered" : {
"filter" : {
"and": [
{
"nested" : {
"path" : "skills",
"filter" : {
"bool" : {
"must" : [
{
"term" : {"skills.id" : 343}
},
{
"range" : {"skills.level" : {"gt" : 3}}
}
]
}
}
}
},
{
"nested" : {
"path" : "jobs",
"filter" : {
"bool" : {
"must" : [
{
"term" : {"jobs.jobid" : 621}
}
]
}
}
}
}
]
}
}
}
}

Anyone experience with it. Please help me to translate that query use FilterDescriptor.
Thanks in advanced!


(Gabriel Moskovicz) #2

Hi Bien,

This should be what you are looking for:

var result = client.Search<Type>(
		s => s.Query(
				q => q.Filtered(
						f => f.Filter(
								f1 => f1.And(
										a1 => a1.Nested(
												n => n.Path("skills").Filter(
														nf => nf.Bool(
																nf1 => nf1.Must(
																		m1 => m1.Term("skills.id", 343),
																		m1 => m1.Range(r1 => r1.OnField("skills.level").Greater(3))
																		)
																	)
																)
													),
									a2 => a2.Nested(
											n => n.Path("jobs").Filter(
													nf => nf.Bool(b => b.Must(bm => bm.Term("jobs.job.id", 621)))
																)
													)
					)
			)
	)));

Thanks!

--Gabriel


(system) #3