# How to make range filter on a multi-field field?

**URL:** <https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653>\
**Category:** Elasticsearch\
**Created:** [August 4, 2020, 6:36am UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653 "2020-08-04T06:36:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![opsuthar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opsuthar/32/54216_2.png) [@opsuthar](https://discuss.elastic.co/u/opsuthar)\
**Post date:** [August 4, 2020, 6:36am UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/1 "2020-08-04T06:36:56Z")

</div>

Here is the mapping file, I am using:

```auto
{

    "settings": {

        "number_of_shards": 2

    },

    "mappings": {

        "properties": {

            "SensitiveInfoTypeData": {

                "type": "nested",

                "properties": {

                    "Id": {

                        "type": "keyword"

                    },

                    "Count": {

                        "type": "keyword"

                    },

                    "Confidence": {

                        "type": "keyword",

                        "fields": {

                            "Raw": {

                                "type": "long"

                            }

                        }

                    }

                }

            }

        }

    }

}

```

PUT

```auto
{
    "SensitiveInfoTypeData": [
        {
            "Id": "Record1_id1",
            "confidence": 70,
            "confidence1": 70,
            "count": 1
        },
        {
            "Id": "Record2_id2",
            "confidence": 80,
            "confidence1": 80,
            "count": 2
        }
    ]
}

```

Question:

1. How do I make a range query on the confidence field which has multi-field "keyword" & "long". This is what I am trying

```auto
{
    "query": {
        "nested": {
            "path": "SensitiveInfoTypeData",
            "query": {
                "range": {
                    "SensitiveInfoTypeData.confidence": {
                        "gt": 70,
                        "lt": 100
                    }
                }
            }
        }
    }
}

```

which is returning results as expected but I think it is working on the "keyword" and not on the "long" raw field. Could someone help me out with the right Range query here which will work on the Raw field inside confidence?

---

<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:** [August 4, 2020, 9:03am UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/2 "2020-08-04T09:03:58Z")

</div>

Wild guess. If you look at your mapping you probably have a field named `Confidence` and another one named `confidence`.

---

<div class="post-metadata">

**Author:** ![opsuthar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opsuthar/32/54216_2.png) [@opsuthar](https://discuss.elastic.co/u/opsuthar)\
**Post date:** [August 4, 2020, 10:57am UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/3 "2020-08-04T10:57:50Z")

</div>

Thanks @dadoonet for the pointers. I can see another field appearing "confidence" on the mapping file after I ingest documents.

But I don't see this field getting generated in the mapping file in our PPE environment. Is there any setting which forces not to generate another field ?

---

<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:** [August 4, 2020, 11:14am UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/4 "2020-08-04T11:14:32Z")

</div>

Can't tell. May be you are not exactly doing the same thing in both envs?

> [@opsuthar](#):
>
> But I don't see this field getting generated in the mapping file in our PPE environment. Is there any setting which forces not to generate another field ?

Yes. See [dynamic | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html)

---

<div class="post-metadata">

**Author:** ![opsuthar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opsuthar/32/54216_2.png) [@opsuthar](https://discuss.elastic.co/u/opsuthar)\
**Post date:** [August 4, 2020, 11:27am UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/5 "2020-08-04T11:27:38Z")

</div>

For us the dynamic =false which explains why new field it not being generated.

But still not able to understand what is the point of "Raw" field here? Isn't there an another way to reference the 'long' type 'Raw' field in the Query?

When "dynamic=false' then there is no point of below "fields' in the mapping file. Right?

```auto
"fields": {
                            "Raw": {

                                "type": "long"

                            }
}

```

---

<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:** [August 4, 2020, 11:57am UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/6 "2020-08-04T11:57:00Z")

</div>

If you don't need it, don't specify it in the mapping.

---

<div class="post-metadata">

**Author:** ![opsuthar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opsuthar/32/54216_2.png) [@opsuthar](https://discuss.elastic.co/u/opsuthar)\
**Post date:** [August 4, 2020, 2:01pm UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/7 "2020-08-04T14:01:23Z")

</div>

@dadoonet,

I meant is there any significance of below with flag "dynamic=false"?

```auto
"fields": {
                            "Raw": {

                                "type": "long"

                            }
}

```

---

<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:** [August 4, 2020, 4:34pm UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/8 "2020-08-04T16:34:27Z")

</div>

I don't know. I'd need a full example to understand.

---

<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:** [September 1, 2020, 4:34pm UTC](https://discuss.elastic.co/t/how-to-make-range-filter-on-a-multi-field-field/243653/9 "2020-09-01T16:34:30Z")

</div>

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