# How to use a doc field to search another doc?

**URL:** <https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431>\
**Category:** Elasticsearch\
**Created:** [April 17, 2020, 2:21am UTC](https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431 "2020-04-17T02:21:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanbekotori](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kanbekotori](https://discuss.elastic.co/u/kanbekotori)\
**Post date:** [April 17, 2020, 2:21am UTC](https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431/1 "2020-04-17T02:21:34Z")

</div>

customer doc

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

```

workflow doc

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

```

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

```json
{
  "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.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 17, 2020, 2:39am UTC](https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431/2 "2020-04-17T02:39:22Z")

</div>

What's the relationship between `sellerId` and `customerId`,?

---

<div class="post-metadata">

**Author:** ![kanbekotori](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kanbekotori](https://discuss.elastic.co/u/kanbekotori)\
**Post date:** [April 17, 2020, 3:13am UTC](https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431/3 "2020-04-17T03:13:49Z")

</div>

`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`.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 17, 2020, 4:53am UTC](https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431/4 "2020-04-17T04:53:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kanbekotori](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kanbekotori](https://discuss.elastic.co/u/kanbekotori)\
**Post date:** [April 17, 2020, 5:59am UTC](https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431/5 "2020-04-17T05:59:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 15, 2020, 5:59am UTC](https://discuss.elastic.co/t/how-to-use-a-doc-field-to-search-another-doc/228431/6 "2020-05-15T05:59:22Z")

</div>

Closed on May 15, 2020, 5:59am UTC

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