我正在尝试查询Demandware(SFCC(API以使用日期范围提取订单。 开机自检orders_search有效,但似乎效率极低。 首先,我提取所有数据,然后过滤结果。
我想简单地查询日期范围,但我不知道该怎么做。 帮助。
{
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对象。
{
"query" :
{
"filtered_query": {
"query": { match_all_query: {} },
"filter": {
"range_filter": {
"field": "creation_date",
"from": "2016-01-01T00:00:00.000Z"
}
}
}
},
"select" : "(**)"
}