# Java API for field Properties

**URL:** <https://discuss.elastic.co/t/java-api-for-field-properties/3032>\
**Category:** Elasticsearch\
**Created:** [June 21, 2010, 8:12pm UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032 "2010-06-21T20:12:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Doyle](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@Samuel\_Doyle](https://discuss.elastic.co/u/Samuel_Doyle)\
**Post date:** [June 21, 2010, 8:12pm UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/1 "2010-06-21T20:12:10Z")

</div>

Hi,

What is the API for building up property fields specifics such as analyzed,  
type, null\_value and boost values for example?

Thanks

---

<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:** [June 21, 2010, 8:40pm UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/2 "2010-06-21T20:40:56Z")

</div>

You need to build the mappings either using the json builder (xcontent  
builder), using a json string, or using a Map that represents the structure  
and then use the put mapping API (or the create index, which allows to  
specify mappings) to add them. There is no statically typed API for that  
yet.

-shay.banon

On Mon, Jun 21, 2010 at 11:12 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:

> Hi,
> 
> What is the API for building up property fields specifics such as analyzed,  
> type, null\_value and boost values for example?
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![Samuel\_Doyle](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@Samuel\_Doyle](https://discuss.elastic.co/u/Samuel_Doyle)\
**Post date:** [June 21, 2010, 10:47pm UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/3 "2010-06-21T22:47:22Z")

</div>

Alright, I'm trying to create the properties object using:  
XContentBuilder propertiesBuilder = jsonBuilder().startObject("properties")

and I receive the following exception

Can not write a field name, expecting a value  
org.elasticsearch.common.jackson.JsonGenerationException: Can not write a  
field name, expecting a value  
at  
org.elasticsearch.common.jackson.impl.JsonGeneratorBase.\_reportError(JsonGeneratorBase.java:428)  
at  
org.elasticsearch.common.jackson.impl.JsonGeneratorBase.writeFieldName(JsonGeneratorBase.java:207)  
at  
org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:64)  
at  
org.elasticsearch.common.xcontent.builder.XContentBuilder.field(XContentBuilder.java:146)  
at  
org.elasticsearch.common.xcontent.builder.XContentBuilder.startObject(XContentBuilder.java:91)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
at java.lang.reflect.Method.invoke(Method.java:597)  
at  
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)  
at  
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)  
at  
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)  
at  
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)  
at  
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)

I was assuming to create this object and add those properties to it.

On Mon, Jun 21, 2010 at 1:40 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> You need to build the mappings either using the json builder (xcontent  
> builder), using a json string, or using a Map that represents the structure  
> and then use the put mapping API (or the create index, which allows to  
> specify mappings) to add them. There is no statically typed API for that  
> yet.
> 
> -shay.banon
> 
> On Mon, Jun 21, 2010 at 11:12 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> 
> > Hi,
> > 
> > What is the API for building up property fields specifics such as  
> > analyzed, type, null\_value and boost values for example?
> > 
> > Thanks

---

<div class="post-metadata">

**Author:** ![Samuel\_Doyle](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@Samuel\_Doyle](https://discuss.elastic.co/u/Samuel_Doyle)\
**Post date:** [June 21, 2010, 10:57pm UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/4 "2010-06-21T22:57:07Z")

</div>

To be more precise here is the code I'm trying to execute prior to sending  
the field values:

// 2.) Build up the properties metadata for the fields  
def type = builtIndex.indexTypes[0] // only one atm

```
  IndexRequest propertiesRequest = indexRequest("${builtIndex.name}")
  propertiesRequest.type("${type.name}")

  XContentBuilder propertiesBuilder =

```

jsonBuilder().startObject("properties")  
type.fields.each() { field -\>  
// process each fields metadata (properties)  
propertiesBuilder.startObject("${field.name}") // start of the  
properties for the field

```
        field.fieldProperties.each() { property ->
          propertiesBuilder.field("${property.name}",

```

"${property.value}")  
}

```
      propertiesBuilder.endObject() // field properties
    }
  propertiesBuilder.endObject() // properties object

  propertiesRequest.source(propertiesBuilder)
  IndexResponse propertiesResponse =
        client.index(propertiesRequest).actionGet()

```

Thanks

On Mon, Jun 21, 2010 at 3:47 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com) wrote:

> Alright, I'm trying to create the properties object using:  
> XContentBuilder propertiesBuilder = jsonBuilder().startObject("properties")
> 
> and I receive the following exception
> 
> Can not write a field name, expecting a value  
> org.elasticsearch.common.jackson.JsonGenerationException: Can not write a  
> field name, expecting a value  
> at  
> org.elasticsearch.common.jackson.impl.JsonGeneratorBase.\_reportError(JsonGeneratorBase.java:428)  
> at  
> org.elasticsearch.common.jackson.impl.JsonGeneratorBase.writeFieldName(JsonGeneratorBase.java:207)  
> at  
> org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:64)  
> at  
> org.elasticsearch.common.xcontent.builder.XContentBuilder.field(XContentBuilder.java:146)  
> at  
> org.elasticsearch.common.xcontent.builder.XContentBuilder.startObject(XContentBuilder.java:91)  
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> at  
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> at  
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> at java.lang.reflect.Method.invoke(Method.java:597)  
> at  
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)  
> at  
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)  
> at  
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)  
> at  
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)  
> at  
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> 
> I was assuming to create this object and add those properties to it.
> 
> On Mon, Jun 21, 2010 at 1:40 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > You need to build the mappings either using the json builder (xcontent  
> > builder), using a json string, or using a Map that represents the structure  
> > and then use the put mapping API (or the create index, which allows to  
> > specify mappings) to add them. There is no statically typed API for that  
> > yet.
> > 
> > -shay.banon
> > 
> > On Mon, Jun 21, 2010 at 11:12 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > What is the API for building up property fields specifics such as  
> > > analyzed, type, null\_value and boost values for example?
> > > 
> > > Thanks

---

<div class="post-metadata">

**Author:** ![Paul\_Loy](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Paul\_Loy](https://discuss.elastic.co/u/Paul_Loy)\
**Post date:** [June 22, 2010, 8:18am UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/5 "2010-06-22T08:18:27Z")

</div>

I think you need an object around the whole lot, e.g.:

{ //startObject()  
properties : { //startObject("properties")  
...  
}  
}

On Mon, Jun 21, 2010 at 11:57 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:

> To be more precise here is the code I'm trying to execute prior to sending  
> the field values:
> 
> // 2.) Build up the properties metadata for the fields  
> def type = builtIndex.indexTypes[0] // only one atm
> 
> ```
> IndexRequest propertiesRequest = indexRequest("${builtIndex.name}")
> propertiesRequest.type("${type.name}")
> 
> XContentBuilder propertiesBuilder =
> 
> ```
> 
> jsonBuilder().startObject("properties")  
> type.fields.each() { field -\>  
> // process each fields metadata (properties)  
> propertiesBuilder.startObject("${field.name}") // start of the  
> properties for the field
> 
> ```
> field.fieldProperties.each() { property ->
> propertiesBuilder.field("${property.name}",
> 
> ```
> 
> "${property.value}")  
> }
> 
> ```
> propertiesBuilder.endObject() // field properties
> }
> propertiesBuilder.endObject() // properties object
> 
> propertiesRequest.source(propertiesBuilder)
> IndexResponse propertiesResponse =
> client.index(propertiesRequest).actionGet()
> 
> ```
> 
> Thanks
> 
> On Mon, Jun 21, 2010 at 3:47 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> 
> > Alright, I'm trying to create the properties object using:  
> > XContentBuilder propertiesBuilder =  
> > jsonBuilder().startObject("properties")
> > 
> > and I receive the following exception
> > 
> > Can not write a field name, expecting a value  
> > org.elasticsearch.common.jackson.JsonGenerationException: Can not write a  
> > field name, expecting a value  
> > at  
> > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.\_reportError(JsonGeneratorBase.java:428)  
> > at  
> > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.writeFieldName(JsonGeneratorBase.java:207)  
> > at  
> > org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:64)  
> > at  
> > org.elasticsearch.common.xcontent.builder.XContentBuilder.field(XContentBuilder.java:146)  
> > at  
> > org.elasticsearch.common.xcontent.builder.XContentBuilder.startObject(XContentBuilder.java:91)  
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > at  
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > at  
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > at java.lang.reflect.Method.invoke(Method.java:597)  
> > at  
> > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)  
> > at  
> > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)  
> > at  
> > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)  
> > at  
> > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)  
> > at  
> > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> > 
> > I was assuming to create this object and add those properties to it.
> > 
> > On Mon, Jun 21, 2010 at 1:40 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> > 
> > > wrote:
> > 
> > > You need to build the mappings either using the json builder (xcontent  
> > > builder), using a json string, or using a Map that represents the structure  
> > > and then use the put mapping API (or the create index, which allows to  
> > > specify mappings) to add them. There is no statically typed API for that  
> > > yet.
> > > 
> > > -shay.banon
> > > 
> > > On Mon, Jun 21, 2010 at 11:12 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > What is the API for building up property fields specifics such as  
> > > > analyzed, type, null\_value and boost values for example?
> > > > 
> > > > Thanks

## --

Paul Loy  
[paul@keteracel.com](mailto:paul@keteracel.com)  
[http://www.keteracel.com/paul](http://www.keteracel.com/paul)

---

<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:** [June 22, 2010, 9:28am UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/6 "2010-06-22T09:28:44Z")

</div>

Here is the docs for the put mapping API:  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/admin/indices/put\_mapping/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/put_mapping/).  
You shouldn't use the index API to set the mappings. And, the above is  
correct, you need to startObject and then endObject.

Note, if you use groovy, then you can use a closure to define the mappings  
(similar to grails json builder) in a similar manner that you can use it to  
index data.

-shay.banon

On Tue, Jun 22, 2010 at 11:18 AM, Paul Loy [keteracel@gmail.com](mailto:keteracel@gmail.com) wrote:

> I think you need an object around the whole lot, e.g.:
> 
> { //startObject()  
> properties : { //startObject("properties")  
> ...
> 
> }  
> }
> 
> On Mon, Jun 21, 2010 at 11:57 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> 
> > To be more precise here is the code I'm trying to execute prior to sending  
> > the field values:
> > 
> > // 2.) Build up the properties metadata for the fields  
> > def type = builtIndex.indexTypes[0] // only one atm
> > 
> > ```
> > IndexRequest propertiesRequest = indexRequest("${builtIndex.name}")
> > propertiesRequest.type("${type.name}")
> > 
> > XContentBuilder propertiesBuilder =
> > 
> > ```
> > 
> > jsonBuilder().startObject("properties")  
> > type.fields.each() { field -\>  
> > // process each fields metadata (properties)  
> > propertiesBuilder.startObject("${field.name}") // start of the  
> > properties for the field
> > 
> > ```
> > field.fieldProperties.each() { property ->
> > propertiesBuilder.field("${property.name}",
> > 
> > ```
> > 
> > "${property.value}")  
> > }
> > 
> > ```
> > propertiesBuilder.endObject() // field properties
> > }
> > propertiesBuilder.endObject() // properties object
> > 
> > propertiesRequest.source(propertiesBuilder)
> > IndexResponse propertiesResponse =
> > client.index(propertiesRequest).actionGet()
> > 
> > ```
> > 
> > Thanks
> > 
> > On Mon, Jun 21, 2010 at 3:47 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > 
> > > Alright, I'm trying to create the properties object using:  
> > > XContentBuilder propertiesBuilder =  
> > > jsonBuilder().startObject("properties")
> > > 
> > > and I receive the following exception
> > > 
> > > Can not write a field name, expecting a value  
> > > org.elasticsearch.common.jackson.JsonGenerationException: Can not write a  
> > > field name, expecting a value  
> > > at  
> > > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.\_reportError(JsonGeneratorBase.java:428)  
> > > at  
> > > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.writeFieldName(JsonGeneratorBase.java:207)  
> > > at  
> > > org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:64)  
> > > at  
> > > org.elasticsearch.common.xcontent.builder.XContentBuilder.field(XContentBuilder.java:146)  
> > > at  
> > > org.elasticsearch.common.xcontent.builder.XContentBuilder.startObject(XContentBuilder.java:91)  
> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > > at  
> > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > > at  
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > > at java.lang.reflect.Method.invoke(Method.java:597)  
> > > at  
> > > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)  
> > > at  
> > > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)  
> > > at  
> > > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)  
> > > at  
> > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)  
> > > at  
> > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> > > 
> > > I was assuming to create this object and add those properties to it.
> > > 
> > > On Mon, Jun 21, 2010 at 1:40 PM, Shay Banon \<  
> > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > 
> > > > You need to build the mappings either using the json builder (xcontent  
> > > > builder), using a json string, or using a Map that represents the structure  
> > > > and then use the put mapping API (or the create index, which allows to  
> > > > specify mappings) to add them. There is no statically typed API for that  
> > > > yet.
> > > > 
> > > > -shay.banon
> > > > 
> > > > On Mon, Jun 21, 2010 at 11:12 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > What is the API for building up property fields specifics such as  
> > > > > analyzed, type, null\_value and boost values for example?
> > > > > 
> > > > > Thanks
> 
> ## --
> 
> Paul Loy  
> [paul@keteracel.com](mailto:paul@keteracel.com)  
> [http://www.keteracel.com/paul](http://www.keteracel.com/paul)

---

<div class="post-metadata">

**Author:** ![Samuel\_Doyle](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@Samuel\_Doyle](https://discuss.elastic.co/u/Samuel_Doyle)\
**Post date:** [June 22, 2010, 9:33am UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/7 "2010-06-22T09:33:33Z")

</div>

I was using both start and end object in my case and I wasn't adding any  
additional mappings during the indexing.  
It looks as if there are default ones set for you if you don't provide it  
during an index request but the same is not done during a create request.  
For example I did not add an analyzed property for a field during create but  
it looks as if it was added on index.

I'm assuming this based on the log messages I encountered.

Thanks

On Tue, Jun 22, 2010 at 2:28 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Here is the docs for the put mapping API:  
> [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/admin/indices/put\_mapping/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/put_mapping/).  
> You shouldn't use the index API to set the mappings. And, the above is  
> correct, you need to startObject and then endObject.
> 
> Note, if you use groovy, then you can use a closure to define the mappings  
> (similar to grails json builder) in a similar manner that you can use it to  
> index data.
> 
> -shay.banon
> 
> On Tue, Jun 22, 2010 at 11:18 AM, Paul Loy [keteracel@gmail.com](mailto:keteracel@gmail.com) wrote:
> 
> > I think you need an object around the whole lot, e.g.:
> > 
> > { //startObject()  
> > properties : { //startObject("properties")  
> > ...
> > 
> > }  
> > }
> > 
> > On Mon, Jun 21, 2010 at 11:57 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > 
> > > To be more precise here is the code I'm trying to execute prior to  
> > > sending the field values:
> > > 
> > > // 2.) Build up the properties metadata for the fields  
> > > def type = builtIndex.indexTypes[0] // only one atm
> > > 
> > > ```
> > > IndexRequest propertiesRequest = indexRequest("${builtIndex.name}")
> > > propertiesRequest.type("${type.name}")
> > > 
> > > XContentBuilder propertiesBuilder =
> > > 
> > > ```
> > > 
> > > jsonBuilder().startObject("properties")  
> > > type.fields.each() { field -\>  
> > > // process each fields metadata (properties)  
> > > propertiesBuilder.startObject("${field.name}") // start of the  
> > > properties for the field
> > > 
> > > ```
> > > field.fieldProperties.each() { property ->
> > > propertiesBuilder.field("${property.name}",
> > > 
> > > ```
> > > 
> > > "${property.value}")  
> > > }
> > > 
> > > ```
> > > propertiesBuilder.endObject() // field properties
> > > }
> > > propertiesBuilder.endObject() // properties object
> > > 
> > > propertiesRequest.source(propertiesBuilder)
> > > IndexResponse propertiesResponse =
> > > client.index(propertiesRequest).actionGet()
> > > 
> > > ```
> > > 
> > > Thanks
> > > 
> > > On Mon, Jun 21, 2010 at 3:47 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > > 
> > > > Alright, I'm trying to create the properties object using:  
> > > > XContentBuilder propertiesBuilder =  
> > > > jsonBuilder().startObject("properties")
> > > > 
> > > > and I receive the following exception
> > > > 
> > > > Can not write a field name, expecting a value  
> > > > org.elasticsearch.common.jackson.JsonGenerationException: Can not write  
> > > > a field name, expecting a value  
> > > > at  
> > > > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.\_reportError(JsonGeneratorBase.java:428)  
> > > > at  
> > > > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.writeFieldName(JsonGeneratorBase.java:207)  
> > > > at  
> > > > org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:64)  
> > > > at  
> > > > org.elasticsearch.common.xcontent.builder.XContentBuilder.field(XContentBuilder.java:146)  
> > > > at  
> > > > org.elasticsearch.common.xcontent.builder.XContentBuilder.startObject(XContentBuilder.java:91)  
> > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > > > at  
> > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > > > at  
> > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > > > at java.lang.reflect.Method.invoke(Method.java:597)  
> > > > at  
> > > > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)  
> > > > at  
> > > > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)  
> > > > at  
> > > > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)  
> > > > at  
> > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)  
> > > > at  
> > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> > > > 
> > > > I was assuming to create this object and add those properties to it.
> > > > 
> > > > On Mon, Jun 21, 2010 at 1:40 PM, Shay Banon \<  
> > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > 
> > > > > You need to build the mappings either using the json builder (xcontent  
> > > > > builder), using a json string, or using a Map that represents the structure  
> > > > > and then use the put mapping API (or the create index, which allows to  
> > > > > specify mappings) to add them. There is no statically typed API for that  
> > > > > yet.
> > > > > 
> > > > > -shay.banon
> > > > > 
> > > > > On Mon, Jun 21, 2010 at 11:12 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > What is the API for building up property fields specifics such as  
> > > > > > analyzed, type, null\_value and boost values for example?
> > > > > > 
> > > > > > Thanks
> > 
> > ## --
> > 
> > Paul Loy  
> > [paul@keteracel.com](mailto:paul@keteracel.com)  
> > [http://www.keteracel.com/paul](http://www.keteracel.com/paul)

---

<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:** [June 22, 2010, 10:04am UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/8 "2010-06-22T10:04:12Z")

</div>

Ahh, yes, basically, if you don't specify something, it uses the default,  
which is stored in the mappings.

-shay.banon

On Tue, Jun 22, 2010 at 12:33 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:

> I was using both start and end object in my case and I wasn't adding any  
> additional mappings during the indexing.  
> It looks as if there are default ones set for you if you don't provide it  
> during an index request but the same is not done during a create request.  
> For example I did not add an analyzed property for a field during create  
> but it looks as if it was added on index.
> 
> I'm assuming this based on the log messages I encountered.
> 
> Thanks
> 
> On Tue, Jun 22, 2010 at 2:28 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > Here is the docs for the put mapping API:  
> > [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/admin/indices/put\_mapping/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/put_mapping/).  
> > You shouldn't use the index API to set the mappings. And, the above is  
> > correct, you need to startObject and then endObject.
> > 
> > Note, if you use groovy, then you can use a closure to define the mappings  
> > (similar to grails json builder) in a similar manner that you can use it to  
> > index data.
> > 
> > -shay.banon
> > 
> > On Tue, Jun 22, 2010 at 11:18 AM, Paul Loy [keteracel@gmail.com](mailto:keteracel@gmail.com) wrote:
> > 
> > > I think you need an object around the whole lot, e.g.:
> > > 
> > > { //startObject()  
> > > properties : { //startObject("properties")  
> > > ...
> > > 
> > > }  
> > > }
> > > 
> > > On Mon, Jun 21, 2010 at 11:57 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > > 
> > > > To be more precise here is the code I'm trying to execute prior to  
> > > > sending the field values:
> > > > 
> > > > // 2.) Build up the properties metadata for the fields  
> > > > def type = builtIndex.indexTypes[0] // only one atm
> > > > 
> > > > ```
> > > > IndexRequest propertiesRequest =
> > > > 
> > > > ```
> > > > 
> > > > indexRequest("${builtIndex.name}")  
> > > > propertiesRequest.type("${type.name}")
> > > > 
> > > > ```
> > > > XContentBuilder propertiesBuilder =
> > > > 
> > > > ```
> > > > 
> > > > jsonBuilder().startObject("properties")  
> > > > type.fields.each() { field -\>  
> > > > // process each fields metadata (properties)  
> > > > propertiesBuilder.startObject("${field.name}") // start of  
> > > > the properties for the field
> > > > 
> > > > ```
> > > > field.fieldProperties.each() { property ->
> > > > propertiesBuilder.field("${property.name}",
> > > > 
> > > > ```
> > > > 
> > > > "${property.value}")  
> > > > }
> > > > 
> > > > ```
> > > > propertiesBuilder.endObject() // field properties
> > > > }
> > > > propertiesBuilder.endObject() // properties object
> > > > 
> > > > propertiesRequest.source(propertiesBuilder)
> > > > IndexResponse propertiesResponse =
> > > > client.index(propertiesRequest).actionGet()
> > > > 
> > > > ```
> > > > 
> > > > Thanks
> > > > 
> > > > On Mon, Jun 21, 2010 at 3:47 PM, Samuel Doyle [samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)wrote:
> > > > 
> > > > > Alright, I'm trying to create the properties object using:  
> > > > > XContentBuilder propertiesBuilder =  
> > > > > jsonBuilder().startObject("properties")
> > > > > 
> > > > > and I receive the following exception
> > > > > 
> > > > > Can not write a field name, expecting a value  
> > > > > org.elasticsearch.common.jackson.JsonGenerationException: Can not write  
> > > > > a field name, expecting a value  
> > > > > at  
> > > > > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.\_reportError(JsonGeneratorBase.java:428)  
> > > > > at  
> > > > > org.elasticsearch.common.jackson.impl.JsonGeneratorBase.writeFieldName(JsonGeneratorBase.java:207)  
> > > > > at  
> > > > > org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:64)  
> > > > > at  
> > > > > org.elasticsearch.common.xcontent.builder.XContentBuilder.field(XContentBuilder.java:146)  
> > > > > at  
> > > > > org.elasticsearch.common.xcontent.builder.XContentBuilder.startObject(XContentBuilder.java:91)  
> > > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> > > > > at  
> > > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
> > > > > at  
> > > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
> > > > > at java.lang.reflect.Method.invoke(Method.java:597)  
> > > > > at  
> > > > > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)  
> > > > > at  
> > > > > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)  
> > > > > at  
> > > > > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)  
> > > > > at  
> > > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)  
> > > > > at  
> > > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> > > > > 
> > > > > I was assuming to create this object and add those properties to it.
> > > > > 
> > > > > On Mon, Jun 21, 2010 at 1:40 PM, Shay Banon \<  
> > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > 
> > > > > > You need to build the mappings either using the json builder (xcontent  
> > > > > > builder), using a json string, or using a Map that represents the structure  
> > > > > > and then use the put mapping API (or the create index, which allows to  
> > > > > > specify mappings) to add them. There is no statically typed API for that  
> > > > > > yet.
> > > > > > 
> > > > > > -shay.banon
> > > > > > 
> > > > > > On Mon, Jun 21, 2010 at 11:12 PM, Samuel Doyle \<[samueldoyle@gmail.com](mailto:samueldoyle@gmail.com)
> > > > > > 
> > > > > > > wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > What is the API for building up property fields specifics such as  
> > > > > > > analyzed, type, null\_value and boost values for example?
> > > > > > > 
> > > > > > > Thanks
> > > 
> > > ## --
> > > 
> > > Paul Loy  
> > > [paul@keteracel.com](mailto:paul@keteracel.com)  
> > > [http://www.keteracel.com/paul](http://www.keteracel.com/paul)

---

<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, 4:23am UTC](https://discuss.elastic.co/t/java-api-for-field-properties/3032/9 "2017-07-06T04:23:04Z")

</div>


