# Scala elastic4s usage question

**URL:** <https://discuss.elastic.co/t/scala-elastic4s-usage-question/17966>\
**Category:** Elasticsearch\
**Created:** [June 6, 2014, 7:25pm UTC](https://discuss.elastic.co/t/scala-elastic4s-usage-question/17966 "2014-06-06T19:25:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [June 6, 2014, 7:25pm UTC](https://discuss.elastic.co/t/scala-elastic4s-usage-question/17966/1 "2014-06-06T19:25:12Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/10398958-4755-478f-a3f7-3f1b77aca67d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![sksamuel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sksamuel/32/682_2.png) [@sksamuel](https://discuss.elastic.co/u/sksamuel)\
**Post date:** [June 8, 2014, 11:32am UTC](https://discuss.elastic.co/t/scala-elastic4s-usage-question/17966/2 "2014-06-08T11:32:33Z")

</div>

"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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/f79f8ae4-666d-4c9f-9e14-c25a269f61e7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:23am UTC](https://discuss.elastic.co/t/scala-elastic4s-usage-question/17966/3 "2017-07-06T01:23:56Z")

</div>


