那么这里所谓的按日期查询索引是指的是之前索引名称也要按日期来建立,比如下面这样的一个索引的建立请求如:http://localhost:9200/accountdetail-2021.08.23/type1/1put

请求体:{"AccountID": "2021.08.23","Available": "可用资金","Balance": "期货结算准备金","BrokerID": "经纪公司代码","CashIn": "资金差额",

"CloseProfit": "平仓盈亏","Commission": "手续费","Credit": "信用额度","CurrMargin": "当前保证金总额","CurrencyID": "币种代码",

"DeliveryMargin": "投资者交割保证金","Deposit": "入金金额","ExchangeDeliveryMargin": "交易所交割保证金","ExchangeMargin": "交易所保证金",

"FrozenCash": "冻结的资金","FrozenCommission": "冻结的手续费","FrozenMargin": "冻结的保证金","FundMortgageAvailable": "货币质押余额",

"FundMortgageIn": "货币质入金额","FundMortgageOut": "货币质出金额","Interest": "利息收入","InterestBase": "利息基数","Mortgage": "质押金额",

"MortgageableFund": "可质押货币金额","PositionProfit": "持仓盈亏","PreBalance": "上次结算准备金","PreCredit": "上次信用额度",

"PreDeposit": "上次存款额","PreFundMortgageIn": "上次货币质入金额","PreFundMortgageOut": "上次货币质出金额","PreMargin": "上次占用的保证金",

"PreMortgage": "上次质押金额","Reserve": "基本准备金","ReserveBalance": "保底期货结算准备金","SettlementID": "结算编号","SpecProductCloseProfit": "特殊产品持仓盈亏",

"SpecProductCommission": "特殊产品手续费","SpecProductExchangeMargin": "特殊产品交易所保证金","SpecProductFrozenCommission": "特殊产品冻结手续费",

"SpecProductFrozenMargin": "特殊产品冻结保证金","SpecProductMargin": "特殊产品占用保证金","SpecProductPositionProfit": "特殊产品持仓盈亏",

"SpecProductPositionProfitByAlg": "根据持仓盈亏算法计算的特殊产品持仓盈亏","TradingDay": "交易日","Withdraw": "出金金额","WithdrawQuota": "可取资金"

}那么上面这个索引名称中日期部分”2021.08.23”正好是2天之前的日期,因为今天是2021.08.25那么我们一个简单的按日期查询两天前的索引就可以这样来写了如:http://localhost:9200//_searchget。

响应结果:{"took": 4,"timed_out":false,"_shards": {"total": 1,"successful": 1,"skipped": ,"failed":},"hits": {

"total": {"value": 1,"relation": "eq"},"max_score": 1.0,"hits": [{"_index": "accountdetail-2021.08.23",

"_type": "type1","_id": "1","_score": 1.0,"_source": {"AccountID": "2021.08.23","Available": "可用资金","Balance": "期货结算准备金",

"BrokerID": "经纪公司代码","CashIn": "资金差额","CloseProfit": "平仓盈亏","Commission": "手续费","Credit": "信用额度","CurrMargin": "当前保证金总额",

"CurrencyID": "币种代码","DeliveryMargin": "投资者交割保证金","Deposit": "入金金额","ExchangeDeliveryMargin": "交易所交割保证金",

"ExchangeMargin": "交易所保证金","FrozenCash": "冻结的资金","FrozenCommission": "冻结的手续费","FrozenMargin": "冻结的保证金",

"FundMortgageAvailable": "货币质押余额","FundMortgageIn": "货币质入金额","FundMortgageOut": "货币质出金额","Interest": "利息收入",

"InterestBase": "利息基数","Mortgage": "质押金额","MortgageableFund": "可质押货币金额","PositionProfit": "持仓盈亏","PreBalance": "上次结算准备金",

"PreCredit": "上次信用额度","PreDeposit": "上次存款额","PreFundMortgageIn": "上次货币质入金额","PreFundMortgageOut": "上次货币质出金额",

"PreMargin": "上次占用的保证金","PreMortgage": "上次质押金额","Reserve": "基本准备金","ReserveBalance": "保底期货结算准备金","SettlementID": "结算编号",

"SpecProductCloseProfit": "特殊产品持仓盈亏","SpecProductCommission": "特殊产品手续费","SpecProductExchangeMargin": "特殊产品交易所保证金",

"SpecProductFrozenCommission": "特殊产品冻结手续费","SpecProductFrozenMargin": "特殊产品冻结保证金","SpecProductMargin": "特殊产品占用保证金",

"SpecProductPositionProfit": "特殊产品持仓盈亏","SpecProductPositionProfitByAlg": "根据持仓盈亏算法计算的特殊产品持仓盈亏","TradingDay": "交易日",

"Withdraw": "出金金额","WithdrawQuota": "可取资金"}}]}}那么上面这个请求就是命中了这个索引那么同样的,如果我创建一个这样的请求:http://localhost:9200/accountdetail-2021.07.25/type1/6put

请求体:{"AccountID": "2021.07.25","bbq": "上次货币质入金额","PreFundMortgageOut": "上次货币质出金额","PreMargin": "上次占用的保证金",

"PreMortgage": "上次质押金额"}那么我使用日期查询http://localhost:9200//_searchget也能查到:{"took": 1,"timed_out":false,"_shards": {

"total": 1,"successful": 1,"skipped": ,"failed":},"hits": {"total": {"value": 1,"relation": "eq"},"max_score": 1.0,

"hits": [{"_index": "accountdetail-2021.07.25","_type": "type1","_id": "6","_score": 1.0,"_source": {

"AccountID": "2021.07.25","bbq": "上次货币质入金额","PreFundMortgageOut": "上次货币质出金额","PreMargin": "上次占用的保证金",

"PreMortgage": "上次质押金额"}}]}}因为现在是2021.08.25,那么now-M就正好表示的是一个月之前的,而上面这次创建的这个索引也正好就是一个月之前的索引那么我们再来创建一个当前时间的索引,不包含日的,现在时间是2021.08.25,那么我们创建一个索引就是2021.08的索引如:。

http://localhost:9200/accountdetail-2021.08/type1/6put请求头:{"AccountID": "2021.08","bbq": "上次货币质入金额","PreFundMortgageOut": "上次货币质出金额",

"PreMargin": "上次占用的保证金","PreMortgage": "上次质押金额"}那么要查看2021.08的索引,则get请求如:http://localhost:9200//_search

也是可以匹配搜索到该索引的从以上这些索引查询请求示例中可以发现这些个请求有一个规律:http://localhost:9200//_searchstatic_name是表达式的一部分,在每个日期数学索引(如帐户详细信息)中保持相同。

date_math_expr包含动态确定日期和时间的数学表达式,如now-2ddate_format包含日期在索引中写入的格式,如YYYY.MM.dd 如果今天的日期是2021年8月25日,则将返回accountdetail-2021.08.23。

还有就是说上面这种搜索是对索引名进行匹配的,并不是对索引中的类型或者数据进行匹配的。