# Searching or filtering on a multi value field

**URL:** <https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364>\
**Category:** Elasticsearch\
**Created:** [June 6, 2017, 7:05am UTC](https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364 "2017-06-06T07:05:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![boCyrill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bocyrill/32/17114_2.png) [@boCyrill](https://discuss.elastic.co/u/boCyrill)\
**Post date:** [June 6, 2017, 7:05am UTC](https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364/1 "2017-06-06T07:05:23Z")

</div>

Hello Everyone,

I have a MySQL database with a table that contains 2 importants fields **title** and **age\_range**.

That table saves documents like this `45;60` for documents designed for users between 45 and 60 years old, `18;70` for users between 18 and 70 years old and so on...

Now I would like to fire the query `test` on the field **title** with the filter `18;50` for the field **age\_range** that will return all documents matching `test` with the age range field contained in this interval including the 2 the 2 cases above for example.

For instance, I use Logstash to index my data.  
How can I achieve this?  
Any treatment to do while indexing my data with logstash?  
Any filter, tokenizer to use while indexing using ES analyzer?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 6, 2017, 8:35am UTC](https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364/2 "2017-06-06T08:35:18Z")

</div>

No need to transform the data before it gets indexed in elasticsearch.

As for mapping, I'd recommend using [Range datatype](https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html) which is designed for that kind of use case IMO.

I'd do something like:

```auto
PUT range_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "age": {
          "type": "integer_range"
        }
      }
    }
  }
}

PUT range_index/my_type/1
{
  "title": "whatever",
  "age" : { 
    "gte" : 45,
    "lte" : 60
  }
}
PUT range_index/my_type/1
{
  "title": "whatever",
  "age" : { 
    "gte" : 18,
    "lte" : 70
  }
}

```

Then search with something like:

```auto
POST range_index/_search
{
  "query" : {
    "range" : {
      "age" : { 
        "gte" : 18,
        "lte" : 50 
      }
    }
  }
}

```

But again, you need to parse your documents before indexing them.  
You can use a grok filter in logstash or use ingest grok processor in elasticsearch directly.

---

<div class="post-metadata">

**Author:** ![boCyrill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bocyrill/32/17114_2.png) [@boCyrill](https://discuss.elastic.co/u/boCyrill)\
**Post date:** [June 6, 2017, 9:35am UTC](https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364/3 "2017-06-06T09:35:31Z")

</div>

Thank you for your quick response @dadoonet .

But it seams the answer you provided is for integer fields? or maybe am I wrong?  
Because as I said the ages are saved in a string field (MySQL varchar) in this format `'bottom_age;top_age'` for each row.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 6, 2017, 11:10am UTC](https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364/4 "2017-06-06T11:10:48Z")

</div>

Yes. This is why I said that:

> But again, you need to parse your documents before indexing them.  
> You can use a grok filter in logstash or use ingest grok processor in elasticsearch directly.

---

<div class="post-metadata">

**Author:** ![boCyrill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bocyrill/32/17114_2.png) [@boCyrill](https://discuss.elastic.co/u/boCyrill)\
**Post date:** [June 6, 2017, 11:16am UTC](https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364/5 "2017-06-06T11:16:12Z")

</div>

Ooh Alright.  
Sorry I missed that part.  
Thank you very much

---

<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:** [July 4, 2017, 11:16am UTC](https://discuss.elastic.co/t/searching-or-filtering-on-a-multi-value-field/88364/6 "2017-07-04T11:16:22Z")

</div>

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