Selecting documents in elasticsearch

I am trying to select documents that contain another document in
elasticsearch grouped by id field.. I think it is more understable by
the next example:

"doc1": {
   "id": "firstid"
   "my_field":"1"
}
"doc2": {
   "id": "firstid"
   "my_field":"12"
}
"doc3": {
   "id": "firstid"
   "my_field":"123"
}
"doc4": {
   "id": "secondid"
   "my_field":"1234"
}
"doc5": {
   "id": "firstid"
   "my_field":"12"
}
"doc6": {
   "id": "firstid"
   "my_field":"1"
}
"doc7": {
    "id":"firstid"
    "my_field":"qwerty" 
 }
 "doc8" {
     "id": "firstid"
     "my_field": "qwer"
  }

I want output to be

"doc3":{
   "id": "firstid"
   "my_field":"123"
 }
 "doc4": {
   "id": "secondid"
   "my_field":"1234"
}
"doc7": {
    "id":"firstid"
    "my_field":"qwerty" 
 }

Thank you in advance!

First: use ``` around code blocks so they are more readable. I've used my magic admin powers to add them in for you.

Second: I can't figure out what you are trying to do from your example.

1 Like

@nik9000 sorry, I am new in using this wonderful service.. I am asking for a help from discuss audience to write a query that will output me unique documents that follow next rules:

  1. Documents grouped by the id's
  2. Then grouped documents should be grouped by the content of field "my_field"
    So, from the example we get "doc3", which has "id":"firstid" and its field "my_field" contains doc1["my_field"] and doc2["my_field"] content..

Hope, I have explained enough:D

You might be looking for the terms aggregation, not a query at all.

Thank you very much, I will look for it. @nik9000

@nik9000 Hi:D can you send query please?

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