# Querying for populated field mappings given a specific field/value

**URL:** <https://discuss.elastic.co/t/querying-for-populated-field-mappings-given-a-specific-field-value/14370>\
**Category:** Elasticsearch\
**Created:** [November 12, 2013, 10:47pm UTC](https://discuss.elastic.co/t/querying-for-populated-field-mappings-given-a-specific-field-value/14370 "2013-11-12T22:47:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Anderson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_anderson/32/1988_2.png) [@Andrew\_Anderson](https://discuss.elastic.co/u/Andrew_Anderson)\
**Post date:** [November 12, 2013, 10:47pm UTC](https://discuss.elastic.co/t/querying-for-populated-field-mappings-given-a-specific-field-value/14370/1 "2013-11-12T22:47:58Z")

</div>

Hi All,

I'd like to inspect the \_mapping of given a specific field/value in an ES  
index of a specific type. The way we set up our data (due to design of  
nesting/parent-child relationships) was to put them all under one type,  
then have a subType field. Unfortunately, as data is indexed and the  
\_mapping schema dynamically builds out, the \_mapping shows all the possible  
fields of that type, and I can't query or filter the \_mapping. This makes  
sense (\_mapping is more of a config schema file per se, not a search API as  
I understand it), but is there any workaround that could give us the  
desired result? Here is an example:

index: Farm  
type: Animal

So localhost:9200/Farm/Animal/\_mapping retrieves the mapping. But in our  
data we have a field animalType. I want to get the 'populated' fields, i.e.  
the dynamically built mappings file, but only when animalType is Cow, for  
instance.

A clear workaround is to redesign our data and index to look like  
/Farm/Cow, /Farm/Sheep, in which case /Farm/Cow/\_mapping would return the  
desired fields for the Cow type. But that disrupts other aspects of our  
data design due for maintaining parent-children.

Is it possible to query/generate a field list when we have Farm/Animal and  
animalType is Cow, without scanning all data? Sort of like a facets query,  
where the facet is on the field names (instead of a specific field), the  
counts being how often they are used! It would be like faceting on the  
schema, if it were searchable. Sorry if that's confusing!

Thanks for any ideas!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 14, 2013, 11:16am UTC](https://discuss.elastic.co/t/querying-for-populated-field-mappings-given-a-specific-field-value/14370/2 "2013-11-14T11:16:00Z")

</div>

Hey,

On the top of my head I do not think that this is possible. The reason for  
this is, that the type is just another metadata field in the data  
structure, which is used to store the indexed documents. On that level we  
do not have any type information, as all documents regardless of its type  
of an index are stored in that data structure.

I also dont have any awesome idea to work around that at the moment.

--Alex

On Tue, Nov 12, 2013 at 11:47 PM, Andrew Anderson [picasandrew@gmail.com](mailto:picasandrew@gmail.com)wrote:

> Hi All,
> 
> I'd like to inspect the \_mapping of given a specific field/value in an ES  
> index of a specific type. The way we set up our data (due to design of  
> nesting/parent-child relationships) was to put them all under one type,  
> then have a subType field. Unfortunately, as data is indexed and the  
> \_mapping schema dynamically builds out, the \_mapping shows all the possible  
> fields of that type, and I can't query or filter the \_mapping. This makes  
> sense (\_mapping is more of a config schema file per se, not a search API as  
> I understand it), but is there any workaround that could give us the  
> desired result? Here is an example:
> 
> index: Farm  
> type: Animal
> 
> So localhost:9200/Farm/Animal/\_mapping retrieves the mapping. But in our  
> data we have a field animalType. I want to get the 'populated' fields, i.e.  
> the dynamically built mappings file, but only when animalType is Cow, for  
> instance.
> 
> A clear workaround is to redesign our data and index to look like  
> /Farm/Cow, /Farm/Sheep, in which case /Farm/Cow/\_mapping would return the  
> desired fields for the Cow type. But that disrupts other aspects of our  
> data design due for maintaining parent-children.
> 
> Is it possible to query/generate a field list when we have Farm/Animal and  
> animalType is Cow, without scanning all data? Sort of like a facets query,  
> where the facet is on the field names (instead of a specific field), the  
> counts being how often they are used! It would be like faceting on the  
> schema, if it were searchable. Sorry if that's confusing!
> 
> Thanks for any ideas!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:07am UTC](https://discuss.elastic.co/t/querying-for-populated-field-mappings-given-a-specific-field-value/14370/3 "2017-07-06T02:07:03Z")

</div>


