How to use a doc field to search another doc?

customer doc

{
	"id": "123",
	"name": "alibaba",
	"sellerId": "111"
}

workflow doc

{
	"id": "100",
	"title": "hello",
	"customerId": "123"
}

I want to search workflow documents with sallerId, it look like

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "sellerId": {
              "value": "111"
            }
          }
        }
      ]
    }
  }
}

I can't use parent-child, because customer is not really a parent of workflow, some workflow doc dosen't has customer infomation. How could i use customer.sellerId to search workflow doc.

What's the relationship between sellerId and customerId,?

workflow doc may has customerId, and customer doc must has sellerId, Seller can search its own workflow doc.
I know which customer doc belongs to the seller, but I don't know which workflow doc belongs to the seller.
The customerId in workflow doc is the id of customer doc, and customer doc has sellerId.

That is a join, which Elasticsearch does not support. I would recommend denormalizing by storing the seller is on the workflow.

Yes, that is my final way. It's hard to maintain sellerId on workflow in my project.

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