Document Retreive


(Teddy) #1

I have two indices

  1. index A
  2. index B

both the indices has different information
but
each index has a field named "employee_id"

I need to retrieve all information of a employee with id 1 from both the indices.

Since both indices have same field value employee_id, i need

indexA.employee_id==1

indexB.employee_id==1 //something like this

together to be filtered


(David Pilato) #2
DELETE test1 
DELETE test2
PUT test1/doc/1
{
  "employee_id": 1
}
PUT test1/doc/2
{
  "employee_id": 2
}
PUT test2/doc/1
{
  "employee_id": 1
}
GET test1,test2/_search
{
  "query": {
    "term": {
      "employee_id": {
        "value": 1
      }
    }
  }
}

Gives:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 10,
    "successful": 10,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1,
    "hits": [
      {
        "_index": "test1",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "employee_id": 1
        }
      },
      {
        "_index": "test2",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "employee_id": 1
        }
      }
    ]
  }
}

(Teddy) #3

The requirement as follows.

 GET indexa,indexb/_search?
    {
      "_source": ["employee_id from indexa","employee_name from indexa","employee_branch from indexb","sum of salary from indexb"],
      "query": {
        "match": { 
          "employee_id": "5"
        }
      }
    }

I need all the information as a single record document.


(David Pilato) #4

There is no JOIN in elasticsearch. Apart this https://www.elastic.co/guide/en/elasticsearch/reference/6.1/parent-join.html

May be tell more about the use case?


(Teddy) #5

Join can be used within an Index, as I have multiple table, this is of no use to me.
though thanks.

What do u need in usecase??


(David Pilato) #6

What do u need in usecase??

What kind of problem are you trying to solve?
If you denormalize the data, may be you can solve it?


(system) #7

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