Hi,
Good Day!
I am currently using Elastic search 5.2 upgraded from 0.9 followed by 2.3. Right now working on project which displays the opportunities based on Talent segment, location and career level. I am expecting that latest opportunities should be displayed and its depend on "Posted Date" field in opportunities data.
But right now its not happening, its giving unordered data. Below is screenshot for your reference.
Also sharing some code snippet with you.
Old:
List<BaseQuery> careerLevelQuery = new List<BaseQuery>();
careerLevelQuery.Add(Nest.Query.CustomScore(cs => cs.Query(t => t.Term(Constants.FilterCareerLevel, careerLevel.ToString())).Script("30")));
careerLevelQuery.Add(Nest.Query.CustomScore(cs => cs.Query(t => t.Term(Constants.FilterCareerLevel, aboveCareerLevel.ToString())).Script("12")));
careerLevelQuery.Add(Nest.Query.CustomScore(cs => cs.Query(t => t.Term(Constants.FilterCareerLevel, belowCareerLevel.ToString())).Script("1")));
List<BaseFilter> mustNotnonGCPFilters = new List<BaseFilter>();
List<BaseFilter> mustClause = new List<BaseFilter>();
mustClause.Add(Nest.Filter.Term("status", "Open"));
_search = _search.Query(fq => fq.Filtered(
q => q.Query(
qd => qd.Bool(
b => b.Must(
m => m.Bool(bt => bt.Should(talentSegmentQuery.ToArray())),
m => m.Bool(bl => bl.Should(locationAndCountryQuery.ToArray()).MinimumNumberShouldMatch(1)),
m => m.Bool(bt => bt.Should(careerLevelQuery.ToArray()))
).Should(otherGDVQuery.ToArray()).DisableCoord()))
.Filter(flt => flt.Bool(
b => b.Must(mustClause.ToArray())
.MustNot(mustNotnonGCPFilters.ToArray())
))));
New:
List<QueryContainer> careerLevelQuery = new List<QueryContainer>();
careerLevelQuery.Add(Query<Position>.FunctionScore(cs => cs.Query(t => t.Term(Constants.FilterCareerLevel, careerLevel.ToString()))
.Functions(f => f.ScriptScore(sc => sc.Script(s => s.Inline("30"))))));
careerLevelQuery.Add(Query<Position>.FunctionScore(cs => cs.Query(t => t.Term(Constants.FilterCareerLevel, aboveCareerLevel.ToString()))
.Functions(f => f.ScriptScore(sc => sc.Script(s => s.Inline("12"))))));
careerLevelQuery.Add(Query<Position>.FunctionScore(cs => cs.Query(t => t.Term(Constants.FilterCareerLevel, belowCareerLevel.ToString()))
.Functions(f => f.ScriptScore(sc => sc.Script(s => s.Inline("1"))))));
SearchDescriptor<Position> _search = new SearchDescriptor<Position>();
_search = _search.Index(string.Join(",", objIndices.ElasticIndices)).Type(string.Join(",", objIndices.ElasticTypes))
.From(from)
.Size(size);
List<QueryContainer> mustClause = new List<QueryContainer>();
mustClause.Add(Query<Position>.Bool(x => x.Filter(y => y.Term("status", "Open"))));
List<QueryContainer> mustNotnonGCPFilters = new List<QueryContainer>();
_search = _search.Query(
fq => fq.Bool(
q => q.Must(
qd => qd.Bool(
b => b.Must(
m => m.Bool(bt => bt.Should(talentSegmentQuery.ToArray())),
m => m.Bool(bl => bl.Should(locationAndCountryQuery.ToArray()).MinimumShouldMatch(1)),
m => m.Bool(bt => bt.Should(careerLevelQuery.ToArray()))
).Should(otherGDVQuery.ToArray()).DisableCoord()))
.Filter(flt => flt.Bool(
b => b.Must(mustClause.ToArray())
.MustNot(mustNotnonGCPFilters.ToArray())
))));
And Finally...
ISearchResponse<Position> response = new SearchResponse<Position>();
response = client.Search<Position>(_search);
Can you please let me know why this is happening.
Thanks!