# Search on the same field multiple times with different filters and intersect the results

**URL:** <https://discuss.elastic.co/t/search-on-the-same-field-multiple-times-with-different-filters-and-intersect-the-results/257312>\
**Category:** Elasticsearch\
**Created:** [December 2, 2020, 7:15am UTC](https://discuss.elastic.co/t/search-on-the-same-field-multiple-times-with-different-filters-and-intersect-the-results/257312 "2020-12-02T07:15:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amir\_Mirahmady](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_mirahmady/32/78953_2.png) [@Amir\_Mirahmady](https://discuss.elastic.co/u/Amir_Mirahmady)\
**Post date:** [December 2, 2020, 7:15am UTC](https://discuss.elastic.co/t/search-on-the-same-field-multiple-times-with-different-filters-and-intersect-the-results/257312/1 "2020-12-02T07:15:16Z")

</div>

Hi . I'm working on a project that records in my index have dynamic values . I mean I have a field named fieldvalue that can be a date or a text or a number and every record is piece of data from each user . The reason why used this because users have dynamic fields and save dynamic data into multiple forms . It's a formbuilder project so every field is dynamic.  
I have multiple search filters and i want to find users that match those filters like text filter or date filter or number filter . filters are dynamic too . I want to know is there a way that I find users that match filters by search the same field (filedvalue in my index) in elastic. data is like below:

```auto
 {
        "_index" : "fieldvaluedata",
        "_type" : "_doc",
        "_id" : "118",
        "_score" : 1.0,
        "_source" : {
          "id" : 118,
          "userid" : 8,
          "userFormsId" : 195163,
          "recordId" : 64213,
          "formId" : 41,
          "fieldid" : 124,
          "fieldtype" : 10,
          "fieldName" : "field_2",
          "fieldvalue" : "May 8 2017 1:45PM",
          "createdate" : "2017-07-15T00:00:00"
        }
      },
      {
        "_index" : "fieldvaluedata",
        "_type" : "_doc",
        "_id" : "119",
        "_score" : 1.0,
        "_source" : {
          "id" : 119,
          "userid" : 8,
          "userFormsId" : 195163,
          "recordId" : 64213,
          "formId" : 41,
          "fieldid" : 123,
          "fieldtype" : 0,
          "fieldName" : "field_1",
          "fieldvalue" : "",
          "createdate" : "2017-07-15T00:00:00"
        }
      },
      {
        "_index" : "fieldvaluedata",
        "_type" : "_doc",
        "_id" : "120",
        "_score" : 1.0,
        "_source" : {
          "id" : 120,
          "userid" : 8,
          "userFormsId" : 195163,
          "recordId" : 64213,
          "formId" : 41,
          "fieldid" : 125,
          "fieldtype" : 0,
          "fieldName" : "field_3",
          "fieldvalue" : "باشگاه مشتریان شهرداری",
          "createdate" : "2017-07-15T00:00:00"
        }
      }

```

my search is like filter users that field value containts " some text" and field value is lower than 20 (for age) and date filter like lower than 2020-02-10 and send back users that match these conditions.

---

<div class="post-metadata">

**Author:** ![Amir\_Mirahmady](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_mirahmady/32/78953_2.png) [@Amir\_Mirahmady](https://discuss.elastic.co/u/Amir_Mirahmady)\
**Post date:** [December 6, 2020, 8:43am UTC](https://discuss.elastic.co/t/search-on-the-same-field-multiple-times-with-different-filters-and-intersect-the-results/257312/2 "2020-12-06T08:43:20Z")

</div>

I found the solution using filters aggregation I could search on same field multiple times and then intersect the results I could get what I wanted.

---

<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 3, 2021, 8:43am UTC](https://discuss.elastic.co/t/search-on-the-same-field-multiple-times-with-different-filters-and-intersect-the-results/257312/3 "2021-01-03T08:43:24Z")

</div>

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