# Field query

**URL:** <https://discuss.elastic.co/t/field-query/9656>\
**Category:** Elasticsearch\
**Created:** [November 9, 2012, 10:00pm UTC](https://discuss.elastic.co/t/field-query/9656 "2012-11-09T22:00:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Smolyak](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Michael\_Smolyak](https://discuss.elastic.co/u/Michael_Smolyak)\
**Post date:** [November 9, 2012, 10:00pm UTC](https://discuss.elastic.co/t/field-query/9656/1 "2012-11-09T22:00:27Z")

</div>

I have the following section as part of my document - it represents "weakly  
typed" custom fields.

- customFields: [
  - {
  - 
    - id: 4055
    - class: DropDownCustomField
    - customFieldName: color
    - empty: false
    - fieldValueText: blue,orange,mauve  
}

  - {
    - id: 4056
    - class: DropDownCustomField
    - customFieldName: hue
    - empty: false
    - fieldValueText: red,blue  
}  
]

How can I find a parent object (which has field customFileds) where custom  
field color has 'blue' among its values. Currently, I am searching using  
query string

customFieldName:color AND fieldValueText:blue

The problem with my approach that if the object has custom field 'color'  
with value 'red' and custom field 'hue' with value 'blue', that object will  
be among the hits. I need to make sure that field name and field value  
belong to the same custom field (with id 4055 in my example).

How can I achieve that?

Thank you,

Michael

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 10, 2012, 2:16am UTC](https://discuss.elastic.co/t/field-query/9656/2 "2012-11-10T02:16:22Z")

</div>

You need to index customFields as nested objects[http://www.elasticsearch.org/guide/reference/mapping/nested-type.html](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)and wrap "customFieldName:color AND fieldValueText:blue" into a nested  
query[http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)  
.

On Friday, November 9, 2012 5:00:27 PM UTC-5, Michael Smolyak wrote:

> I have the following section as part of my document - it represents  
> "weakly typed" custom fields.
> 
> - customFields: [
> - {
> - 
> - id: 4055
> - class: DropDownCustomField
> - customFieldName: color
> - empty: false
> - fieldValueText: blue,orange,mauve  
> }
> 
> - {
> - id: 4056
> - class: DropDownCustomField
> - customFieldName: hue
> - empty: false
> - fieldValueText: red,blue  
> }  
> ]
> 
> How can I find a parent object (which has field customFileds) where custom  
> field color has 'blue' among its values. Currently, I am searching using  
> query string
> 
> customFieldName:color AND fieldValueText:blue
> 
> The problem with my approach that if the object has custom field 'color'  
> with value 'red' and custom field 'hue' with value 'blue', that object will  
> be among the hits. I need to make sure that field name and field value  
> belong to the same custom field (with id 4055 in my example).
> 
> How can I achieve that?
> 
> Thank you,
> 
> Michael

--

---

<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, 3:05am UTC](https://discuss.elastic.co/t/field-query/9656/3 "2017-07-06T03:05:01Z")

</div>


