Scala elastic4s usage question


(Ramdev Wudali) #1

Hi:
I have started using the scala libraries provided by the elastic4s
libraries. I am running into a problem creating a mapping that has a
straightforward definition (yet it has some complexity).

Example :

{
"index": {
"mappings": {
"OA": {
"properties": {
"AdminStatus": {
"properties": {
"content": {
"type": "string"
},
"effectiveFrom": {
"type": "date",
"format": "dateOptionalTime"
}
}
},
"IsPublicFlag": {
"type": "boolean"
},
"OrganizationAddress": {
"properties": {
"OrganizationAddressCity": {
"type": "string"
},
"OrganizationAddressCountryCode": {
"type": "string"
},
"OrganizationAddressLine1": {
"type": "string"
}
}
}
}
}
}
}
}

I am not able to figure out how to define OrganizationAddress field (which
is a "complex" object.)

if I define it as such :

indexClient.execute {
create index "index" mappings (
"OA" as (
"AdminStatus" as (
"content" typed
StringType,
"effectiveFrom" typed
DateType
),
"IsPublicFlag"
typed BooleanType,

"OrganizationAddress" as (

"OrganizationAddressCity" typed StringType,

"OrganizationAddressLine1" typed StringType,
)
) }

I get a compilation error :
Error:(52, 69) type mismatch;
found : com.sksamuel.elastic4s.mapping.MappingDefinition
required: com.sksamuel.elastic4s.mapping.TypedFieldDefinition
"AdminStatus" as (
^

How can I map complex objects using the Scala interface elastic4s ?

Thanks

Ramdev

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/10398958-4755-478f-a3f7-3f1b77aca67d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Stephen Samuel) #2

"as" is only used to start a mapping definition, ie in the outer block. You
are mapping nested fields, in which case you want to use "nested", or
"inner" depending on your use case.

Here is an example taken from the unit tests:

create.index("users").shards(2).mappings(
"tweets" as (
id typed StringType analyzer KeywordAnalyzer,
"name" typed StringType analyzer KeywordAnalyzer,
"locations" typed GeoPointType validate true normalize true,
"date" typed DateType precisionStep 5,
"size" typed LongType,
"read" typed BooleanType,
"content" typed StringType,
"user" nested (
"name" typed StringType,
"email" typed StringType,
"last" nested {
"lastLogin" typed DateType
}
)
) size true numericDetection true boostNullValue 1.2 boost "myboost"
)

On Friday, June 6, 2014 8:25:12 PM UTC+1, Ramdev Wudali wrote:

Hi:
I have started using the scala libraries provided by the elastic4s
libraries. I am running into a problem creating a mapping that has a
straightforward definition (yet it has some complexity).

Example :

{
"index": {
"mappings": {
"OA": {
"properties": {
"AdminStatus": {
"properties": {
"content": {
"type": "string"
},
"effectiveFrom": {
"type": "date",
"format": "dateOptionalTime"
}
}
},
"IsPublicFlag": {
"type": "boolean"
},
"OrganizationAddress": {
"properties": {
"OrganizationAddressCity": {
"type": "string"
},
"OrganizationAddressCountryCode": {
"type": "string"
},
"OrganizationAddressLine1": {
"type": "string"
}
}
}
}
}
}
}
}

I am not able to figure out how to define OrganizationAddress field
(which is a "complex" object.)

if I define it as such :

indexClient.execute {
create index "index" mappings (
"OA" as (
"AdminStatus" as (
"content" typed
StringType,
"effectiveFrom"
typed DateType
),
"IsPublicFlag"
typed BooleanType,

"OrganizationAddress" as (

"OrganizationAddressCity" typed StringType,

"OrganizationAddressLine1" typed StringType,
)
) }

I get a compilation error :
Error:(52, 69) type mismatch;
found : com.sksamuel.elastic4s.mapping.MappingDefinition
required: com.sksamuel.elastic4s.mapping.TypedFieldDefinition
"AdminStatus" as (
^

How can I map complex objects using the Scala interface elastic4s ?

Thanks

Ramdev

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f79f8ae4-666d-4c9f-9e14-c25a269f61e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #3