gte and format don't match here. Which looks strange to me.
Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.
A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.
Thanks again for your reply.
What im trying to performed its very simple, just querying from my "Event" Documents that match my needs which are:
.Index('custom_Index_array_of_strings_to_look_for')
.Query(
Events.DateField ->GreaterThan ("DateToPrivided")
Events.Datefield -> LowerThanOrEqueals ("DateFromProvided")
&&
Events.Rule that match with my custom "LegacysIdsProvided" inside a Terms Query
)
I'been reading the all "n00bies" section in order to help myself to write properly my query to everybody knows what i am trying to do.
GET index/_search
result = client.Search<Event>(s => s
.Query(q => q
.Bool(b => b
.Filter(f => f
.Terms(t => t
.Field("RuleID")
.Terms(legacyIDs)
)
&&
f.DateRange(dr => dr
.Field("DateTime")
.GreaterThanOrEquals(new DateTime().AddDays(-1))
)
)
)
)
);
Reading the differences between "Context Querys" and "Filter Querys" allow me to understand what i was doing wrong, but unfortunately theres somethings missing up there with my query.
Now i think its quite clear, but if you dont understand it please let me know
If I understand correctly, you're looking to have both the terms query and range query executed in the context of filter clauses of a bool query? If that's the case, your query is almost correct, but
.Filter(...) takes a collection of lambda expressions to express the queries
new DateTime().AddDays(-1) is an unrepresentable date; it is one day less than the smallest representable date in .NET (1/01/0001 12:00:00 AM). I think you want DateTime.Now.AddDays(-1) here
var legacyIDs = new [] { "1", "2" };
var result = client.Search<Event>(s => s
.Query(q => q
.Bool(b => b
.Filter(f => f
.Terms(t => t
.Field("RuleID")
.Terms(legacyIDs)
), f => f
.DateRange(dr => dr
.Field("DateTime")
.GreaterThanOrEquals(DateTime.Now.AddDays(-1))
)
)
)
)
);
With operator overloading, you can create bool queries even more succinctly. Here's the same query but with more concise syntax
var result = client.Search<Event>(s => s
.Query(q => +q
.Terms(t => t
.Field("RuleID")
.Terms(legacyIDs)
) && +q
.DateRange(dr => dr
.Field("DateTime")
.GreaterThanOrEquals(DateTime.Now.AddDays(-1))
)
)
);
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.