How to combine multiple fields values within single field

Dear All.

again i came here from long time with some issue.

i have data inside elastic search like below:-

id name cnt marks
101 ram ind 80.32
101 ram ...... null
101 ram uk 78.3
101 ram us null

now when i search for "name":"ram" it give below output :-
id name cnt marks
101 ram ind 80.32
101 ram ....... null
101 ram uk 78.3
101 ram us null
id name cnt marks
but i need output like below :

id name cnt marks
101 ram ind 80.32
..... ....... ........ null
...... .......... uk 78.3
...... ......... us null

final : we want to stop duplicate records like id,name
please help us:-
...... is nothing here!

Thanks
HadoopHelp

Hi @rameshkr1994,

I believe what you are looking for is aggregations. I am not sure, but you should explore Terms Aggregation.

Link for reference :
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

An Example Query :

GET <index_name>/_search?_source=false
{
  "query": {
    "bool": {
      "filter": [{
          "term": {
            "name": "ram"
          }
        }]
    }
  },
  "aggs": {
    "group_by_id": {
      "terms": {
        "field": "id",
        "size": 1000
      },
      "aggs": {
        "top_hits": {
          "top_hits": {
            "size": 100,
            "_source": ["cnt", "marks"]
          }
        }
      }
    }
  }
}

The above is just a adhoc query. You may need to modify or tweak it a little.

Hope that helps. :slight_smile:

Regards,
Somnath

Hi @somnath.guthula.

thanks for replying !!!

i written this query as per my requirement but not success-ed :

URL : http://LOCALHOST:9200/healthecdemo/_search?_source=false

Query :-1:

{
"query": {
"bool": {
"filter": [{
"term": {
"firstname": "Firstname1"
}
}]
}
},
"aggs": {
"group_by_id": {
"terms": {
"field": "healthrecordkey",
"size": 100
},
"aggs": {
"top_hits": {
"top_hits": {
"size": 100,
"_source": ["sex", "drugname"]
}
}
}
}
}
}

response :-(ERROR)

{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits":
},
"aggregations": {
"group_by_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets":
}
}
}

still not getting this solution!!

as per your gouide i tried ?filter with term is not working here !! if change here filter and term with must and match then result is fetching but previous output is coming ?

Thanks
HadoopHelp

As mentioned earlier, The query would require some tweaking before using it. I am assuming you are using the right keys.

Someone should help out in regards to this. My Apologies.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.