Comments (5)
When I build the query I don't the .Index("indexname") as I wan't to use the DefaultIndex that is set when I create the client
string defaultIndex = "articles_query_tests.";
var settings = new ElasticsearchClientSettings(uri: new Uri(uri))
.DefaultIndex($"{defaultIndex}*")
private SearchRequestDescriptor<Article> CreateSeachRequestDescriptor(int page, int size, int offset, Metadata.Models.Query.Search query)
{
return CreateQuery(query)
.TrackTotalHits(track)
.From(page * offset)
.Size(size)
.Sort(CreateSortOptions(query));
}
from elasticsearch-net.
Thanks @jyrijh, this actually helped me to spot the bug in the generator. I'll fix this in the next patch release.
from elasticsearch-net.
Hi @jyrijh, could you please share your CreateQuery
method?
from elasticsearch-net.
Sure, but it wont tell much
private SearchRequestDescriptor<Article> CreateQuery(Metadata.Models.Query.Search searchQuery)
{
if (searchQuery.Filters.OfType<Metadata.Models.Query.Filter.IddocListFilter>().Any())
{
return CreateIdsQuery(searchQuery);
}
BoolQuery boolQuery = new()
{
Must = CreateMustQueries(searchQuery),
Filter = CreateFilters(searchQuery),
MustNot = CreateNotFilters(searchQuery)
};
SearchRequestDescriptor<Article> search = new();
return search.Query(boolQuery);
}
from elasticsearch-net.
and CreateMustQueries
private List<Query> CreateMustQueries(Metadata.Models.Query.Search searchQuery)
{
List<Query> mustQueries = [];
foreach (var filter in searchQuery.OrFilters.OfType<IHasValueOrDoesNotExistsFilter>())
{
if(filter is DateExistsFilter dateExistsFilter)
{
mustQueries.Add(new BoolQuery()
{
Should =
[
CreateDateComparisonFilter(dateExistsFilter),
new BoolQuery()
{
MustNot = [new ExistsQuery() { Field = dateExistsFilter.FieldName }]
}
]
});
}
if(filter is ServiceTypeFilter IHasTermValueOrDoesNotExistsFilter)
{
mustQueries.Add(new BoolQuery()
{
Should =
[
new TermQuery(((BaseFilter)filter).FieldName) { Value = ((IHasTermValueOrDoesNotExistsFilter)filter).Value },
new BoolQuery()
{
MustNot = [new ExistsQuery() { Field = ((BaseFilter)filter).FieldName }]
}
]
});
}
}
foreach (var filter in searchQuery.Filters.OfType<IMustExistsFilter>())
{
mustQueries.Add(new ExistsQuery() { Field = ((BaseFilter)filter).FieldName });
}
return mustQueries.Count != 0 ? mustQueries: null!;
Query CreateDateComparisonFilter(DateExistsFilter dateExistsFilter) => dateExistsFilter.Comparison switch
{
DateExistsFilter.ComparisonType.Gt => new DateRangeQuery(dateExistsFilter.FieldName) { Gt = _timeProvider.GetUtcNow().DateTime },
DateExistsFilter.ComparisonType.Lt => new DateRangeQuery(dateExistsFilter.FieldName) { Lt = _timeProvider.GetUtcNow().DateTime },
DateExistsFilter.ComparisonType.Gte => new DateRangeQuery(dateExistsFilter.FieldName) { Gte = _timeProvider.GetUtcNow().DateTime },
DateExistsFilter.ComparisonType.Lte => new DateRangeQuery(dateExistsFilter.FieldName) { Lte = _timeProvider.GetUtcNow().DateTime },
_ => throw new NotImplementedException()
};
}
from elasticsearch-net.
Related Issues (20)
- [FEATURE] Elastic 8 Client - Stores Enums as Strings HOT 5
- Cannot use RawJsonQuery HOT 6
- Encountered an unsupported variant tag '' on 'Analysis.INormalizer', which could not be deserialized
- Simplify IndexAsync Abstraction to Infer Index Name from TDocument Type HOT 3
- Lacks the ability to put aggregations into aggregations HOT 5
- Elasticsearch 8.13 documentation not available when NuGet update is available HOT 1
- Deserializing type hierarchies doesn't seem to work HOT 10
- Update index settings with PutSettingsAsync fails with error status code 400: "request body is required" HOT 1
- Failing to deserialize response for `GetIndexAsync` HOT 5
- Cannot retrieve mapping of index with `icu_collation_keyword` field HOT 6
- cannot instantiate new DynamicTemplate when creating index. HOT 4
- Default index is not used in query with 8.13.15 client HOT 1
- Missing properties in aggregation API HOT 3
- Improve documentation for error handling
- Elastic.Transport.UnexpectedTransportException when calling elasticClient.MachineLearning.InferTrainedModelAsync HOT 1
- Support for using input_output option in inference processor
- CI: Automate reference documentation
- Intervals query is missing the option to set Field HOT 3
- Fluent API for composite aggregation sources
- IndexSettingsConverter tries to deserialize routing_path as collection of string even if there is a string in raw JSON response HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-net.