# Index Template

**URL:** <https://discuss.elastic.co/t/index-template/6233>\
**Category:** Elasticsearch\
**Created:** [December 24, 2011, 1:01am UTC](https://discuss.elastic.co/t/index-template/6233 "2011-12-24T01:01:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Padilla](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@Nicholas\_Padilla](https://discuss.elastic.co/u/Nicholas_Padilla)\
**Post date:** [December 24, 2011, 1:01am UTC](https://discuss.elastic.co/t/index-template/6233/1 "2011-12-24T01:01:17Z")

</div>

Hello All!

you can find the code and json examples here:

I am attempting to create an index template using the Java API,  
however, I am having difficulty doing so properly. Let me fill the  
blanks as to what I am trying to accomplish. I have some json stored  
as a string in a MSSQL database. The json represents different forms  
in a uniform format. We will have many of these objects with dynamic  
data and the Index Type's will be based on the unique formId in the  
RDBMS. I would like to query for "datafield" = "First Name" AND  
"datavalue"="Nic\*". I would only expect any records that matched for  
the query. I have seen several locations in the forums that specify  
that I need to use a nested type for the 'dataDisplayFields' field and  
then construct a NestedQuery that uses the dataDisplayFields.datavalue  
and dataDisplayFields.datafield. This way we can ensure we correctly  
get the one record with the First Name and Nic\*. I would think I  
need to use Index Templates so that all indices/types make the  
'dataDisplayFields' a nested object, so i can use the NestedQuery.

I am using the JavaAPI in an embedded mode environment and cannot  
figure out how to add my template so that all indices/types know that  
the 'dataDisplayFields' are of 'nested' type. Any help would be  
appreciated, let me know of any questions or comments!

Thanks and Happy Holidays!

---

<div class="post-metadata">

**Author:** ![Nicholas\_Padilla](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@Nicholas\_Padilla](https://discuss.elastic.co/u/Nicholas_Padilla)\
**Post date:** [December 24, 2011, 1:02am UTC](https://discuss.elastic.co/t/index-template/6233/2 "2011-12-24T01:02:22Z")

</div>

Sorry, forgot to add the gist: [Elastic Search Template/NestedQuery · GitHub](https://gist.github.com/1515839)

On Dec 23, 6:01 pm, Nicholas Padilla [nicho...@monstersoftwarellc.com](mailto:nicho...@monstersoftwarellc.com)  
wrote:

> Hello All!
> 
> you can find the code and json examples here:
> 
> I am attempting to create an index template using the Java API,  
> however, I am having difficulty doing so properly. Let me fill the  
> blanks as to what I am trying to accomplish. I have some json stored  
> as a string in a MSSQL database. The json represents different forms  
> in a uniform format. We will have many of these objects with dynamic  
> data and the Index Type's will be based on the unique formId in the  
> RDBMS. I would like to query for "datafield" = "First Name" AND  
> "datavalue"="Nic\*". I would only expect any records that matched for  
> the query. I have seen several locations in the forums that specify  
> that I need to use a nested type for the 'dataDisplayFields' field and  
> then construct a NestedQuery that uses the dataDisplayFields.datavalue  
> and dataDisplayFields.datafield. This way we can ensure we correctly  
> get the one record with the First Name and Nic\*. I would think I  
> need to use Index Templates so that all indices/types make the  
> 'dataDisplayFields' a nested object, so i can use the NestedQuery.
> 
> I am using the JavaAPI in an embedded mode environment and cannot  
> figure out how to add my template so that all indices/types know that  
> the 'dataDisplayFields' are of 'nested' type. Any help would be  
> appreciated, let me know of any questions or comments!
> 
> Thanks and Happy Holidays!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 25, 2011, 4:39pm UTC](https://discuss.elastic.co/t/index-template/6233/3 "2011-12-25T16:39:57Z")

</div>

The whole template structure is wrong, you just set type to nested in the  
map. Read again how templates are used.

On Sat, Dec 24, 2011 at 3:02 AM, Nicholas Padilla \<  
[nicholas@monstersoftwarellc.com](mailto:nicholas@monstersoftwarellc.com)\> wrote:

> Sorry, forgot to add the gist: [Elastic Search Template/NestedQuery · GitHub](https://gist.github.com/1515839)
> 
> On Dec 23, 6:01 pm, Nicholas Padilla [nicho...@monstersoftwarellc.com](mailto:nicho...@monstersoftwarellc.com)  
> wrote:
> 
> > Hello All!
> > 
> > you can find the code and json examples here:
> > 
> > I am attempting to create an index template using the Java API,  
> > however, I am having difficulty doing so properly. Let me fill the  
> > blanks as to what I am trying to accomplish. I have some json stored  
> > as a string in a MSSQL database. The json represents different forms  
> > in a uniform format. We will have many of these objects with dynamic  
> > data and the Index Type's will be based on the unique formId in the  
> > RDBMS. I would like to query for "datafield" = "First Name" AND  
> > "datavalue"="Nic\*". I would only expect any records that matched for  
> > the query. I have seen several locations in the forums that specify  
> > that I need to use a nested type for the 'dataDisplayFields' field and  
> > then construct a NestedQuery that uses the dataDisplayFields.datavalue  
> > and dataDisplayFields.datafield. This way we can ensure we correctly  
> > get the one record with the First Name and Nic\*. I would think I  
> > need to use Index Templates so that all indices/types make the  
> > 'dataDisplayFields' a nested object, so i can use the NestedQuery.
> > 
> > I am using the JavaAPI in an embedded mode environment and cannot  
> > figure out how to add my template so that all indices/types know that  
> > the 'dataDisplayFields' are of 'nested' type. Any help would be  
> > appreciated, let me know of any questions or comments!
> > 
> > Thanks and Happy Holidays!

---

<div class="post-metadata">

**Author:** ![Nicholas\_Padilla](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@Nicholas\_Padilla](https://discuss.elastic.co/u/Nicholas_Padilla)\
**Post date:** [December 26, 2011, 3:29pm UTC](https://discuss.elastic.co/t/index-template/6233/4 "2011-12-26T15:29:54Z")

</div>

Hey Shay!

Thanks for the response! I have gone over the docs again just to be  
sure I understand what templates are for. My understanding has not  
changed really, I am specifying a Name for the template when creating  
the Request, I am creating a "catch all" expression for the Template  
field so that it applies to all indices. I created my map with just  
the type = nested and added it using the addMapping call. The mapping  
type I was a bit confused on, however, you had told another user that  
by using the _default_ type you can apply to all types within an  
index. This is what I am trying to accomplish. What part of the  
template is syntactically wrong? Which parts do I remove or replace,  
does the map need to contain a key '_default_' and have a map as the  
value to specify the 'type' = 'nested'? Forgive me but I couldn't find  
a concrete example using the java API, your code is really clean and  
abstracted and easy to use. However, I just can't get its usage  
correct on my end. A bit more help, maybe a small example would be  
wonderful. Thanks for your precious time and thanks for a wonderful  
product!

On Dec 25, 9:39 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> The whole template structure is wrong, you just set type to nested in the  
> map. Read again how templates are used.
> 
> On Sat, Dec 24, 2011 at 3:02 AM, Nicholas Padilla \<
> 
> [nicho...@monstersoftwarellc.com](mailto:nicho...@monstersoftwarellc.com)\> wrote:
> 
> > Sorry, forgot to add the gist:[Elastic Search Template/NestedQuery · GitHub](https://gist.github.com/1515839)
> 
> > On Dec 23, 6:01 pm, Nicholas Padilla [nicho...@monstersoftwarellc.com](mailto:nicho...@monstersoftwarellc.com)  
> > wrote:
> > 
> > > Hello All!
> 
> > > you can find the code and json examples here:
> 
> > > I am attempting to create an index template using the Java API,  
> > > however, I am having difficulty doing so properly. Let me fill the  
> > > blanks as to what I am trying to accomplish. I have some json stored  
> > > as a string in a MSSQL database. The json represents different forms  
> > > in a uniform format. We will have many of these objects with dynamic  
> > > data and the Index Type's will be based on the unique formId in the  
> > > RDBMS. I would like to query for "datafield" = "First Name" AND  
> > > "datavalue"="Nic\*". I would only expect any records that matched for  
> > > the query. I have seen several locations in the forums that specify  
> > > that I need to use a nested type for the 'dataDisplayFields' field and  
> > > then construct a NestedQuery that uses the dataDisplayFields.datavalue  
> > > and dataDisplayFields.datafield. This way we can ensure we correctly  
> > > get the one record with the First Name and Nic\*. I would think I  
> > > need to use Index Templates so that all indices/types make the  
> > > 'dataDisplayFields' a nested object, so i can use the NestedQuery.
> 
> > > I am using the JavaAPI in an embedded mode environment and cannot  
> > > figure out how to add my template so that all indices/types know that  
> > > the 'dataDisplayFields' are of 'nested' type. Any help would be  
> > > appreciated, let me know of any questions or comments!
> 
> > > Thanks and Happy Holidays!

---

<div class="post-metadata">

**Author:** ![Nicholas\_Padilla](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@Nicholas\_Padilla](https://discuss.elastic.co/u/Nicholas_Padilla)\
**Post date:** [December 30, 2011, 7:28pm UTC](https://discuss.elastic.co/t/index-template/6233/5 "2011-12-30T19:28:33Z")

</div>

Hello All!

Any help on this? I appreciate any help!

Thanks and Happy New Year!

On Dec 26, 8:29 am, Nicholas Padilla [nicho...@monstersoftwarellc.com](mailto:nicho...@monstersoftwarellc.com)  
wrote:

> Hey Shay!
> 
> Thanks for the response! I have gone over the docs again just to be  
> sure I understand what templates are for. My understanding has not  
> changed really, I am specifying a Name for the template when creating  
> the Request, I am creating a "catch all" expression for the Template  
> field so that it applies to all indices. I created my map with just  
> the type = nested and added it using the addMapping call. The mapping  
> type I was a bit confused on, however, you had told another user that  
> by using the _default_ type you can apply to all types within an  
> index. This is what I am trying to accomplish. What part of the  
> template is syntactically wrong? Which parts do I remove or replace,  
> does the map need to contain a key '_default_' and have a map as the  
> value to specify the 'type' = 'nested'? Forgive me but I couldn't find  
> a concrete example using the java API, your code is really clean and  
> abstracted and easy to use. However, I just can't get its usage  
> correct on my end. A bit more help, maybe a small example would be  
> wonderful. Thanks for your precious time and thanks for a wonderful  
> product!
> 
> On Dec 25, 9:39 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > The whole template structure is wrong, you just set type to nested in the  
> > map. Read again how templates are used.
> 
> > On Sat, Dec 24, 2011 at 3:02 AM, Nicholas Padilla \<
> 
> > [nicho...@monstersoftwarellc.com](mailto:nicho...@monstersoftwarellc.com)\> wrote:
> > 
> > > Sorry, forgot to add the gist:[Elastic Search Template/NestedQuery · GitHub](https://gist.github.com/1515839)
> 
> > > On Dec 23, 6:01 pm, Nicholas Padilla [nicho...@monstersoftwarellc.com](mailto:nicho...@monstersoftwarellc.com)  
> > > wrote:
> > > 
> > > > Hello All!
> 
> > > > you can find the code and json examples here:
> 
> > > > I am attempting to create an index template using the Java API,  
> > > > however, I am having difficulty doing so properly. Let me fill the  
> > > > blanks as to what I am trying to accomplish. I have some json stored  
> > > > as a string in a MSSQL database. The json represents different forms  
> > > > in a uniform format. We will have many of these objects with dynamic  
> > > > data and the Index Type's will be based on the unique formId in the  
> > > > RDBMS. I would like to query for "datafield" = "First Name" AND  
> > > > "datavalue"="Nic\*". I would only expect any records that matched for  
> > > > the query. I have seen several locations in the forums that specify  
> > > > that I need to use a nested type for the 'dataDisplayFields' field and  
> > > > then construct a NestedQuery that uses the dataDisplayFields.datavalue  
> > > > and dataDisplayFields.datafield. This way we can ensure we correctly  
> > > > get the one record with the First Name and Nic\*. I would think I  
> > > > need to use Index Templates so that all indices/types make the  
> > > > 'dataDisplayFields' a nested object, so i can use the NestedQuery.
> 
> > > > I am using the JavaAPI in an embedded mode environment and cannot  
> > > > figure out how to add my template so that all indices/types know that  
> > > > the 'dataDisplayFields' are of 'nested' type. Any help would be  
> > > > appreciated, let me know of any questions or comments!
> 
> > > > Thanks and Happy Holidays!

---

<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:44am UTC](https://discuss.elastic.co/t/index-template/6233/6 "2017-07-06T03:44:06Z")

</div>

Closed on July 6, 2017, 3:44am UTC


