-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Migration issues Templates and Dynamic queries #8189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Been covering this myself and been very reliant on the source code to guide. If it helps though I can share the approach we've been using to refactor existing code. As far as I can make out the concept of ANDs and ORs you had in the NEST client has been remove - and I actually I think this may be a good thing because I don't think they exist conceptually in the search language. So below is an example of how we refactored from using the operators to Action delegates so we didn't have to refactor existing if statements to much, same can be done with for statements and sorts and other things.
We can then refactor / create the search result descriptor as below:
Multiple sorting fields can be addressed in a similar manner:
Your Sort line would then become:
I can't vouch if this is 100% the approach that should be taken. The documentation is very thin on client usage, and doesn't seem to be up to date with the source code or NuGet packages. But it is working for us so far. Based on using upgrading from NEST 7.17.5 to Elastic.Clients.Elasticsearch 8.13.12. Hope people find this helpful. |
Hi @MarkMcDonald, Thanks so much for your reply. I understand that my current code does not have a solution in the new DLL, for me it is not viable make a migration because my project is very big and a have a lot of indexes with dynamic querys and nested querys... i'm really disapointed and indignant.... by the way, do you know something about my first question about Analysis templates? thx again!! |
Could you please post the complete NEST code for what you are trying to achieve? I want to make sure I fully understand your question. The @MarkMcDonald Thank you for providing this example code! This is exactly how it should be done in the current client 🙂 |
hi, @flobernd
await client.Indices.PutTemplateAsync(templateName,t => t.Settings(s => s.Analysis(a => a.Analyzers(an => an
thx so much |
Hi @franquiroz, it seems like these settings are incorrectly modelled in our specification. I'll have a look and try to find out if this is intended or not. |
Hi, i'm trying to migrate my app from NEST to Elastic.Clients.Elasticsearch, so, i have found some blocking issues
1. i Cant create PutTemplateAsync with Analisis
NEST: await client.Indices.PutTemplateAsync(templateName,t => t.Settings(s => s.Analysis(a => a.Analyzers(an => an
.Custom("ana_s_lc", ca => ca.Tokenizer("standard").Filters("lowercase")))
.Normalizers(nm => nm.Custom("nor_lc", c => c.Filters("lowercase")))
.Tokenizers(t => t.PathHierarchy("tok_path", p => p.Delimiter('\')))
.TokenFilters(t => t.Lowercase("lowercase"))));
Elastic.Clients.Elasticsearch: Settings(Func<FluentDictionary<string, object> ??????????????)
2. In NEST i can create a dynamic QueryContainer like that:
implementing the options (a, b, c) dynamically if some conditions are complied...
and so on, with more complex filters like:
void ElasticFilter(ref QueryContainer queryfilters, CustomFilter item, Expression<Func<T, object>> field) where T : class
{
QueryContainer qc = null;
var allValues = item.Value.Split("||").Where(w => !string.IsNullOrEmpty(w));
switch (item.Filter)
{
case StringFilterType.Contains:
foreach (var wc in allValues.Select(f => new QueryContainerDescriptor().Wildcard(t => t.Field(field).Value("" + f.Replace("", "").Replace("\", "\\").Trim() + ""))))
{
qc |= wc;
}
queryfilters &= new QueryContainerDescriptor().Bool(b => b.Must(m => qc));
break;
case StringFilterType.NotContains:
foreach (var wc in allValues.Select(f => new QueryContainerDescriptor().Wildcard(t => t.Field(field).Value("" + f.Replace("", "").Replace("\", "\\").Trim() + ""))))
{
qc |= wc;
}
queryfilters &= new QueryContainerDescriptor().Bool(b => b.MustNot(m => qc));
break;
case StringFilterType.Equals:
foreach (var wc in allValues.Select(f => new QueryContainerDescriptor().Term(t => t.Field(field).Value(f.Trim()))))
{
qc |= wc;
}
queryfilters &= new QueryContainerDescriptor().Bool(b => b.Must(m => qc));
break;
case StringFilterType.NotEquals:
foreach (var wc in allValues.Select(f => new QueryContainerDescriptor().Term(t => t.Field(field).Value(f.Trim()))))
{
qc |= wc;
}
queryfilters &= new QueryContainerDescriptor().Bool(b => b.MustNot(m => qc));
break;
case StringFilterType.StartWith:
foreach (var wc in allValues.Select(f => new QueryContainerDescriptor().Prefix(t => t.Field(field).Value(f.Trim()))))
{
qc |= wc;
}
queryfilters &= new QueryContainerDescriptor().Bool(b => b.Must(m => qc));
break;
case StringFilterType.NotStartWith:
foreach (var wc in allValues.Select(f => new QueryContainerDescriptor().Prefix(t => t.Field(field).Value(f.Trim()))))
{
qc |= wc;
}
queryfilters &= new QueryContainerDescriptor().Bool(b => b.MustNot(m => qc));
break;
}
}
I CAN'T REACH ANY ALTERNATIVE SOLUTION FOR ANY OF MY ISSUES
i hope anyone can help me
THX SO MUCH
The text was updated successfully, but these errors were encountered: