I have a requirement where i need to get an ads impression count for any date range using Elastic Search. By impression count, i refer to get the success property count (where success: true) from ads object collection.
I am using elasticsearch NodeJS module for querying purposes.
Index mapping, Incorrect query and document data structure (the format in which this field gets stored in an Elastic Search document) for ads field are shown below:
Index Mapping
{
"exlg_2017-01": {
"mappings": {
"exlg": {
"_all": {
"enabled": false
},
"_source": {
"includes": [
"*"
]
},
"dynamic_templates": [
{
"settings_for_all_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"ignore_above": 512,
"type": "text"
}
}
}
],
"properties": {
"ads": {
"properties": {
"clicked": {
"type": "boolean"
},
"sectonHash": {
"type": "text"
},
"success": {
"type": "boolean"
}
}
}
}
}
}
}
}
Incorrect Query
{
"query": {
"bool": {
"must": [
{
"range": {
"createdTs": {
"gte": 1490832000000,
"lte": 1490918399999
}
}
},
{
"query_string": {
"analyze_wildcard": true,
"query": "variationId:abcd-1234 AND siteId:12345"
}
}
],
"should": [],
"must_not": []
}
},
"aggs": {
"ADS_IMPRESSION": {
"terms": {
"field": "ads.success"
}
}
},
"size": 0
}
Document data structure
{
"ads": [
{
"sectionHash": "<---md5 value--->",
"success": true
},
{
"sectionHash": "<---md5 value--->",
"success": true
},
{
"sectionMd5": "<---md5 value--->",
"success": true
},
{
"sectionHash": "<---md5 value--->",
"success": true
},
{
"sectionHash": "<---md5 value--->",
"success": false
}
]
}
After some research, a Nested object mapping for this field seems to be a possible solution. The issue with trying out this solution is that there are a lot of analysed documents with above mentioned mapping (~ 1Million) already stored in ElasticSearch which are accessible through Kibana interface for search and aggregation purposes.
If nested object mapping solution would be tried, all previous field indices will be reindexed with this mapping and i wish to avoid this change as of now.
I want to ask whether there is any other way to get an object property count from an array of objects from ElasticSearch other than Nested object mapping?
What query should i build that can return an object property (success) count from an array of objects (ads) by preserving above mapping for ads field?
via Zahin Alwa
No comments:
Post a Comment