Java API for field Properties


(Samuel Doyle) #1

Hi,

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

Thanks


(Shay Banon) #2

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.comwrote:

Hi,

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

Thanks


(Samuel Doyle) #3

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.comwrote:

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.comwrote:

Hi,

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

Thanks


(Samuel Doyle) #4

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 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.comwrote:

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.comwrote:

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) #5

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.comwrote:

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.comwrote:

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

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.comwrote:

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
http://www.keteracel.com/paul


(Shay Banon) #6

Here is the docs for the put mapping API:
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 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.comwrote:

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.comwrote:

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> 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.comwrote:

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
http://www.keteracel.com/paul


(Samuel Doyle) #7

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.comwrote:

Here is the docs for the put mapping API:
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 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.comwrote:

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.comwrote:

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> 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.comwrote:

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
http://www.keteracel.com/paul


(Shay Banon) #8

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.comwrote:

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.comwrote:

Here is the docs for the put mapping API:
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 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.comwrote:

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.comwrote:

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> 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

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
http://www.keteracel.com/paul


(system) #9