搜索日期弹性搜索中的字段值没有时间 [英] Searching Date Field value in ElasticSearch without time
问题描述
我的数据中有一个日期字段为
type:date,
format :dateOptionalTime
现在我的日期字段和值是 -
INITIAL_EXTRACT_DATE:2015-04-02T06:47:57.78 + 05:30
正在搜索的时候,我只是根据2015-04-02的日期进行搜索。
但我得到0结果。
任何人都可以建议如何搜索确切日期,并且是任何日期。
现在我正在尝试这个 -
对于确切日期 -
term:{
IH_PT_DSC:{
value:2015-04-02
}
For date of date -
条款:{
IH_PT_DSC:[
2015-04-02,
2015- 04-03,
2015-04-03
]
}
您可以使用 范围
过滤器,通过在 gte $ c $中使用相同的日期c> /
lte
和格式
参数,您只指定日期部分(即省略时间部分)
{
pre>
constant_score:{
filter:{
range:{
IH_PT_DSC:{
gte:2015-04-02,
lte:2015-04-02,
格式:yyyy-MM-dd
}
}
}
}
}
如果您需要指定多个日期,您也可以轻松实现。
{
constant_score:{
filter:{
range:{
IH_PT_DSC:{
gte :2015-04-01,
lte:2015-04-03,
格式:yyyy-MM-dd
}
}
}
}
}
最后,如果你需要查询不相交日期间隔,只需使用
bool / should
filter:{
constant_score:{
filter:{
bool:{
should:[
{
range:{< --- interval 1
IH_PT_DSC:{
gte:2015-04-01,
lte: 2015-04-03,
格式:yyyy-MM-dd
}
}
},
{
range :{< --- interval 2
IH_PT_DSC:{
gte:2015-04-05,
lte:2015-04-08
格式:yyyy-MM-dd
}
}
},
{
范围:{< ---间隔3
IH_PT_DSC:{
gte:2015-04-10,
lte:2015-04-12,
format :yyyy-MM-dd
}
}
}
]
}
}
}
}
I have one date field in my data as
"type": "date", "format": "dateOptionalTime"
Now My date Field and Value is -
"INITIAL_EXTRACT_DATE" : "2015-04-02T06:47:57.78+05:30"
While searching I am searching based on only date that is "2015-04-02". but I am getting 0 result.
Can anyone suggest how to search exact date and is any of date.
Now I am trying with this -
For Exact Date -
"term": { "IH_PT_DSC": { "value": "2015-04-02" } }
For Is any of date -
"terms": { "IH_PT_DSC": [ "2015-04-02", "2015-04-03", "2015-04-03" ] }
解决方案You can use a
range
filter for this, by using the same date ingte
/lte
and aformat
parameter where you only specify the date part (i.e. leave out the time part){ "constant_score": { "filter": { "range" : { "IH_PT_DSC" : { "gte": "2015-04-02", "lte": "2015-04-02", "format": "yyyy-MM-dd" } } } } }
If you need to specify multiple dates, you can do so easily as well.
{ "constant_score": { "filter": { "range" : { "IH_PT_DSC" : { "gte": "2015-04-01", "lte": "2015-04-03", "format": "yyyy-MM-dd" } } } } }
Finally, if you need to query disjoint date intervals, simply use a
bool/should
filter:{ "constant_score": { "filter": { "bool": { "should": [ { "range": { <--- interval 1 "IH_PT_DSC": { "gte": "2015-04-01", "lte": "2015-04-03", "format": "yyyy-MM-dd" } } }, { "range": { <--- interval 2 "IH_PT_DSC": { "gte": "2015-04-05", "lte": "2015-04-08", "format": "yyyy-MM-dd" } } }, { "range": { <--- interval 3 "IH_PT_DSC": { "gte": "2015-04-10", "lte": "2015-04-12", "format": "yyyy-MM-dd" } } } ] } } } }
这篇关于搜索日期弹性搜索中的字段值没有时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!