0
我试图使用日期范围查询Demandware(SFCC)api以提取订单。 orders_search的POST工作,但它似乎非常低效。首先我拉全部数据,然后我过滤结果。Salesforce Commerce Cloud/Demandware - 按日期范围的OCAPI查询订单
我想简单地查询日期范围,但我无法弄清楚如何做到这一点。帮帮我。
{
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对象。
请把你的答案的简短解释,指出你为什么提出这个解决方案 – sissy