There are some problems in my NEST Client search, can you help me solve it?

  1. I need to find the log with jobid xxx, but the result is different every time after running the following code;
  2. I want to use the CreateTime field in reverse order, the following code is not successful;
  3. I want to implement fuzzy query, but did not understand the example of elastic docs;

Please help me point out the problem in the code,thanks

var searchResponse = await client.SearchAsync < JobElasticDto > (w =>
w.Query(q => q
.Match(m => m
.Field(f => f
.JobInfoId)
.Query(input.JobId.ToString())
)
)
.From(input.SkipCount)
.Size(input.MaxResultCount)
.Sort(w => w.Descending(p => p.CreateTime))
.Query(w =>
{
if(!string.IsNullOrEmpty(input.SourceType))
{
return w.Match(p => p.Field(q => q.SourceType == input.SourceType));
}
return null;
}).Query(w =>
{
if(!string.IsNullOrEmpty(input.Keywords))
{
return w.Match(p => p.Field(q => q.Message.Contains(input.Keywords)));
}
return null;
}));

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:


It looks like .Query(...) is being called multiple times. This call is assignative and not additive, so the last call assigns and replaces any previous assignments. To combine queries into a compound bool query, take a look at the writing queries and writing bool queries documentation.

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