I am using AWS ElasticSearch V6.4, here's my index
{
"jobs": {
"aliases": {},
"mappings": {
"Job": {
"properties": {
"area": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"childUpdate": {
"type": "boolean"
},
"cityName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"companyId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"companyLogo": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"companyName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"countryName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"createdAt": {
"type": "long"
},
"dateExpired": {
"type": "long"
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"designation": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"experienceYears": {
"type": "long"
},
"fullName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"industryId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"industryName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"jobPublished": {
"type": "long"
},
"jobStatus": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"jobType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"location": {
"type": "geo_point"
},
"numberOfCandidatesShortlisted": {
"type": "long"
},
"number_of_applications": {
"type": "long"
},
"primarySkills": {
"properties": {
"orderNumber": {
"type": "long"
},
"value": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"reasonForClosing": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"resume": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"salary": {
"type": "long"
},
"salaryTo": {
"type": "long"
},
"salaryType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"samejobs": {
"type": "long"
},
"stateName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"status": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
},
"normalize": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
},
"updateAt": {
"type": "long"
},
"updatedAt": {
"type": "long"
},
"user": {
"properties": {
"designation": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"fullName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"profileImageUrl": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"userId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"utmSource": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
},
"settings": {
"index": {
"number_of_shards": "5",
"provided_name": "jobs",
"creation_date": "1556099156261",
"analysis": {
"normalizer": {
"my_normalizer": {
"filter": [
"lowercase"
],
"type": "custom"
}
}
},
"number_of_replicas": "1",
"uuid": "tcNbMSODSD-LoIlei0NrpA",
"version": {
"created": "6040299"
}
}
}
} }
I want to group by on userId, title, companyId with count.
I have tried adding one more item(let say samejobs) and add the total count of group by and searching based on that item and ignoring all other items.
GET myindex/_search
{
"_source": {
"includes": [],
"excludes": ["status", "countryId", "stateId", "cityId"]
},
"sort": [{
"updatedAt": {
"order": "desc"
}
}],
"from": 0,
"size": 100,
"query": {
"bool": {
"must": [{
"term": {
"jobStatus": {
"value": "active"
}
}
}, {
"term": {
"status": {
"value": "active"
}
}
}, {
"range": {
"dateExpired": {
"gt": 1568007661898
}
}
}, {
"range": {
"samejobs": {
"gt": 0
}
}
}, {
"multi_match": {
"query": "sales executive",
"type": "phrase_prefix",
"fields": ["title", "industryName", "primarySkills.value.keyword", "secondarySkills"]
}
}, {
"bool": {
"should": [{
"multi_match": {
"query": "Rajkot",
"type": "phrase_prefix",
"fields": ["area", "cityName"]
}
}]
}
}],
"must_not": [],
"filter": {
"geo_distance": {
"distance": "15000km",
"location": {
"lat": 23.0066678,
"lon": 72.5017585
}
}
}
}
}
}
I want the results to be group by userId, companyId & title with pagination. If the approach i am doing is wrong then please suggest the best way to do that.