# Filter documents from search result

**URL:** <https://discuss.elastic.co/t/filter-documents-from-search-result/291965>\
**Category:** Kibana\
**Created:** [December 15, 2021, 12:08pm UTC](https://discuss.elastic.co/t/filter-documents-from-search-result/291965 "2021-12-15T12:08:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev\_test](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dev_test/32/79287_2.png) [@dev\_test](https://discuss.elastic.co/u/dev_test)\
**Post date:** [December 15, 2021, 12:08pm UTC](https://discuss.elastic.co/t/filter-documents-from-search-result/291965/1 "2021-12-15T12:08:30Z")

</div>

Hi,

i have some data on a index in Elasticsearch that it displayed as follow

```auto
"hits" : {
    "total" : {
      "value" : 7,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "fayvo_contacts",
        "_type" : "_doc",
        "_id" : "3c1",
        "_score" : 1.0,
        "_routing" : "1",
        "_source" : {
          "user_id" : 3,
          "user_gender" : 1,
          "user_location" : {
            "lat" : "34.702",
            "lon" : "71.32"
          },
          "joins_field" : {
            "name" : "phone_book",
            "parent" : "1"
          }
        }
      },
      {
        "_index" : "fayvo_contacts",
        "_type" : "_doc",
        "_id" : "4c1",
        "_score" : 1.0,
        "_routing" : "1",
        "_source" : {
          "user_id" : 4,
          "user_gender" : 1,
          "user_location" : {
            "lat" : "34.622",
            "lon" : "71.102"
          },
          "joins_field" : {
            "name" : "phone_book",
            "parent" : "1"
          }
        }
      },
      {
        "_index" : "fayvo_contacts",
        "_type" : "_doc",
        "_id" : "5c1",
        "_score" : 1.0,
        "_routing" : "1",
        "_source" : {
          "user_id" : 5,
          "user_gender" : 0,
          "user_location" : {
            "lat" : "33.712",
            "lon" : "71.212"
          },
          "joins_field" : {
            "name" : "phone_book",
            "parent" : "1"
          }
        }
      },
      {
        "_index" : "fayvo_contacts",
        "_type" : "_doc",
        "_id" : "6c1",
        "_score" : 1.0,
        "_routing" : "1",
        "_source" : {
          "user_id" : 6,
          "user_gender" : 1,
          "user_location" : {
            "lat" : "34.122",
            "lon" : "71.112"
          },
          "joins_field" : {
            "name" : "phone_book",
            "parent" : "1"
          }
        }
      },
      {
        "_index" : "fayvo_contacts",
        "_type" : "_doc",
        "_id" : "2c1",
        "_score" : 1.0,
        "_routing" : "1",
        "_source" : {
          "user_id" : 2,
          "user_gender" : 1,
          "user_location" : {
            "lat" : "34.722",
            "lon" : "71.02"
          },
          "joins_field" : {
            "name" : "phone_book",
            "parent" : "1"
          }
        }
      },
      {
        "_index" : "fayvo_contacts",
        "_type" : "_doc",
        "_id" : "1f2",
        "_score" : 1.0,
        "_routing" : "1",
        "_source" : {
          "user_id" : 2,
          "user_gender" : 1,
          "user_location" : {
            "lat" : "34.722",
            "lon" : "71.02"
          },
          "joins_field" : {
            "name" : "followed",
            "parent" : "1"
          }
        }
      },
      {
        "_index" : "fayvo_contacts",
        "_type" : "_doc",
        "_id" : "1f3",
        "_score" : 1.0,
        "_routing" : "1",
        "_source" : {
          "user_id" : 3,
          "user_gender" : 1,
          "user_location" : {
            "lat" : "34.702",
            "lon" : "71.32"
          },
          "joins_field" : {
            "name" : "followed",
            "parent" : "1"
          }
        }
      }
    ]
  }

```

i want to exclude the documents from the search result for which user\_id field is present in both followed and phone\_book relation.  
i only want the documents with user\_id field only present in phone\_book and not in followed  
is there any way to achieve the result

---

<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:** [January 12, 2022, 12:08pm UTC](https://discuss.elastic.co/t/filter-documents-from-search-result/291965/2 "2022-01-12T12:08:51Z")

</div>

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