Hi,
I have the following mapping:
"page": {
"properties": {
"rawUrl": {
"type": "string",
"index": "not_analyzed"
},
"url": {
"type": "string",
"analyzer": "url_email"
},
"crawls": {
"type": "nested",
"properties": {
"cwlDate": {
"type": "date",
"format": "yyyy-MM-dd",
"index": "not_analyzed"
},
"cwlHour": {
"type": "date",
"format": "HH:mm:ss",
"index": "not_analyzed"
},
"cwlValues": {
"type": "nested",
"properties": {
"cwlType": {
"type": "string",
"index": "not_analyzed"
},
"cwlCode": {
"type": "string",
"index": "not_analyzed"
},
"cwlSelector": {
"type": "string",
"index": "not_analyzed"
},
"cwlValue": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
I am looking for a way to request elastic to get, for exemple:
all documents, where crawls.cwlValues.cwlCode = 'price' and crawls.cwlValues.cwlValue > 20, but only if crawls.cwlValues.cwlValue.cwlDate is the most recent date:
say I have a document where crawls is like:
[{cwlDate: '2016-04-15', cwlValues: [{cwlCode:'price', cwlValue: '19'}]},
{cwlDate: '2016-04-14', cwlValues: [{cwlCode:'price', cwlValue: '21'}]}]
I don't want the document to match, because even if cwlValue > 20, it is when cwlDate is not the last one.
I think it is possible with a scripted query, but I was wondering if there was another way.
Thanks.