Note - I moved all the results to Pastebin, due to the word count limit of this site, sorry for the inconvenience.
When I am running the following query, for grouping by creator_cust_id
in a specific date range:
{
"from":0,
"size":0,
"query":{
"bool":{
"must":[
{
"range":{
"lead_created_time":{
"from":"2019-02-01 00:00:00",
"to":"2019-03-01 00:00:00",
"format":"yyyy-MM-dd HH:mm:ss",
"boost":1.0
}
}
}
],
"adjust_pure_negative":true,
"boost":1.0
}
},
"aggregations":{
"creator_cust_id":{
"terms":{
"field":"creator_cust_id.keyword",
"size":1000,
"min_doc_count":1,
"shard_min_doc_count":0,
"show_term_doc_count_error":false,
"order":[
{
"_count":"desc"
},
{
"_key":"asc"
}
]
},
"aggregations":{
"data_fields":{
"top_hits":{
"from":0,
"size":1,
"version":false,
"explain":false,
"_source":{
"includes":[
"creator.agent_name",
"creator.agent_team"
],
"excludes":[
]
}
}
}
}
}
}
}
I get the proper result with all the desired data (agent_name
, agent_team
), which is: https://pastebin.com/UgFeeK1a
But, when I add a query to get the specific creator_cust_id
, I get proper data in one case (1000013335) and don't get the data in another case (1107221321).
Here are the respective queries with the result:
Getting desired data
{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"lead_created_time": {
"from": "2019-02-01 00:00:00",
"to": "2019-03-01 00:00:00",
"format": "yyyy-MM-dd HH:mm:ss",
"boost": 1
}
}
},
{
"match": {
"creator_cust_id": {
"query": "1000013335",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"creator_cust_id": {
"terms": {
"field": "creator_cust_id.keyword",
"size": 1000,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"data_fields": {
"top_hits": {
"from": 0,
"size": 1,
"version": false,
"explain": false,
"_source": {
"includes": [
"creator.agent_name",
"creator.agent_team"
],
"excludes": []
}
}
}
}
}
}
}
Result : https://pastebin.com/AwJxLb91
Not getting desired data
{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"lead_created_time": {
"from": "2019-02-01 00:00:00",
"to": "2019-03-01 00:00:00",
"format": "yyyy-MM-dd HH:mm:ss",
"boost": 1
}
}
},
{
"match": {
"creator_cust_id": {
"query": "1107221321",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"creator_cust_id": {
"terms": {
"field": "creator_cust_id.keyword",
"size": 1000,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"data_fields": {
"top_hits": {
"from": 0,
"size": 1,
"version": false,
"explain": false,
"_source": {
"includes": [
"creator.agent_name",
"creator.agent_team"
],
"excludes": []
}
}
}
}
}
}
}
Result : https://pastebin.com/Pp9sMTy3
Notice the empty source
field here.
I am not able to understand, why I am getting such a discrepancy, as I have used the query in a lot of aggregations, without any error till now.
I tried it by using Filter Aggregation
and it worked properly, but I can't use Filter Aggregation
in my case. What's the logic behind this difference? How can I solve it using query
?
I know it won't make any difference, but I am using Java High-Level Rest Client, and these queries are made using that only.
Do ask in the comments for any information that is missing, or need explanation.