我正在尝试查询Demandware(SFCC)API以使用日期范围提取订单。对orders_search的POST有效但看起来非常低效。首先,我拉 ALL 数据然后我过滤结果。
我想简单地查询日期范围,但我无法弄清楚如何做到这一点。救命。
{
query : {
filtered_query: {
query: {
term_query: { fields: ["creation_date"], operator: "is_not_null" }
},
filter: {
range_filter: {
field: "creation_date",
from: "2017-08-12T00:00:00.000Z",
to: "2017-08-13T00:00:00.000Z",
from_inclusive: true
}
}
}
}
}
编辑:虽然我解决了最初的问题,但最终会变得更加复杂,因为该服务一次只允许200个响应。首先,您必须提出请求以找出有多少结果,然后多次调用服务以获取数据。下面是与C#一起使用的代码。日期范围作为变量传递。
var m_payload_count = "{ query : { filtered_query: { query: { term_query: { fields: [\"creation_date\"], operator: \"is_not_null\" } }, filter: { range_filter: { field: \"creation_date\", from: \"" + strBeginDateTime + "\", to: \"" + strEndDateTime + "\", from_inclusive: true } } } } }";
// can only get 200 responses at a a time so make a basic call first to get the total
m_response_count = apiClient.UploadString(m_url, m_payload_count);
dynamic m_jsoncount = JsonConvert.DeserializeObject(m_response_count);
// determine number of times of full api call, rounding up. substitute begin/end dates and beginning count placeholder
int m_records = m_jsoncount["total"];
int m_numbercalls = (m_records + (200 - 1)) / 200;
dynamic m_json;
for (int i = 0; i < m_numbercalls; i++)
{
var m_payload = "{ query : { filtered_query: { query: { term_query: { fields: [\"creation_date\"], operator: \"is_not_null\" } }, filter: { range_filter: { field: \"creation_date\", from: \"" + strBeginDateTime + "\", to: \"" + strEndDateTime + "\", from_inclusive: true } } } }, select: \"(**)\", start: " + i * 200 + ", count: 200 }";
m_response = apiClient.UploadString(m_url, m_payload);
m_json = JsonConvert.DeserializeObject(m_response);
省略了代码的其余部分,但它基本上是遍历m_json对象。
答案 0 :(得分:1)
{
"query" :
{
"filtered_query": {
"query": { match_all_query: {} },
"filter": {
"range_filter": {
"field": "creation_date",
"from": "2016-01-01T00:00:00.000Z"
}
}
}
},
"select" : "(**)"
}