# Query specific term value with a specific numeric value

**URL:** <https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149>\
**Category:** Elasticsearch\
**Created:** [May 22, 2015, 7:09am UTC](https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149 "2015-05-22T07:09:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_C\_S\_Yeh](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@Daniel\_C\_S\_Yeh](https://discuss.elastic.co/u/Daniel_C_S_Yeh)\
**Post date:** [May 22, 2015, 7:09am UTC](https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149/1 "2015-05-22T07:09:57Z")

</div>

my mappiing:

{  
"20150520": {  
"mappings": {  
"01": {  
"properties": {  
"rekognition\_tags": {  
"properties": {  
"confidence": {  
"type": "double"  
},  
"tag": {  
"type": "string"  
}  
}  
},  
"url": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}  
}

my query  
{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"query": "sky"  
}  
},  
{  
"range": {  
"confidence": {  
"gt": "0.5"  
}  
}  
}  
]  
}  
}  
}

result (2 hits)  
"\_source": {  
"rekognition\_tags": [  
{  
"tag": "vessel",  
"confidence": 0.7106  
},  
{  
"tag": "boat",  
"confidence": 0.7106  
},  
{  
"tag": "outdoors",  
"confidence": 0.6975  
},  
{  
"tag": "sky",  
"confidence": 0.6957  
},  
{  
"tag": "cloud",  
"confidence": 0.6172  
}  
],  
"url": "[http://zencirclemedia.blob.core.windows.net/media/5c233265cd](http://zencirclemedia.blob.core.windows.net/media/5c233265cd)  
bef5b10929ddb8e12c2bfd.jpg"  
}

```
	  "_source": {
        "rekognition_tags": [
          {
            "tag": "collection",
            "confidence": 0.876
          },
          {
            "tag": "collage",
            "confidence": 0.876
          },
          {
            "tag": "outdoors",
            "confidence": 0.0908
          },
          {
            "tag": "sky",
            "confidence": 0.0898
          },
          {
            "tag": "sunset",
            "confidence": 0.0898
          }
        ],
        "url": "http://zencirclemedia.blob.core.windows.net/media/7dc9a884c3

```

4231987ad15ec3c54b036d.jpg"  
}

the second hit is wrong since sky's confidence is under 0.5, why elasticsearch still returns it?

Thanks

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [May 22, 2015, 1:24pm UTC](https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149/2 "2015-05-22T13:24:02Z")

</div>

Your query is asking for docs containing any tag "sky" and (separately) any tag with confidence value \>0.5.  
Both of these conditions are true.  
To test confidence and tag values of _the same_ object in an array of objects like your rekognition\_tags you need to be more explicit in both the mapping and the query. Take a look at the nested support: [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-nested-type.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-nested-type.html)

Cheers  
Mark

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 22, 2015, 1:56pm UTC](https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149/3 "2015-05-22T13:56:12Z")

</div>

hello @Daniel_C_S_Yeh hear you have a great post to explain the difference between array and nested [https://www.elastic.co/blog/managing-relations-inside-elasticsearch](https://www.elastic.co/blog/managing-relations-inside-elasticsearch)

---

<div class="post-metadata">

**Author:** ![Daniel\_C\_S\_Yeh](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@Daniel\_C\_S\_Yeh](https://discuss.elastic.co/u/Daniel_C_S_Yeh)\
**Post date:** [May 24, 2015, 2:54pm UTC](https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149/4 "2015-05-24T14:54:33Z")

</div>

it is because my mapping is wrong or query is wrong?

is there any query example that I can reference?

thanks

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 26, 2015, 7:38am UTC](https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149/5 "2015-05-26T07:38:09Z")

</div>

hello @Daniel_C_S_Yeh , for use nested you need to change your mapping and your query ! there is an example in the link that i send you, and is important to read this post to understand the difference between inner obj and nested and how defined a nested . [https://www.elastic.co/blog/managing-relations-inside-elasticsearch](https://www.elastic.co/blog/managing-relations-inside-elasticsearch)

---

<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 6, 2017, 12:11am UTC](https://discuss.elastic.co/t/query-specific-term-value-with-a-specific-numeric-value/1149/6 "2017-07-06T00:11:56Z")

</div>


