# Grails: Best practice indexing domain class

**URL:** <https://discuss.elastic.co/t/grails-best-practice-indexing-domain-class/6496>\
**Category:** Elasticsearch\
**Created:** [January 25, 2012, 3:32pm UTC](https://discuss.elastic.co/t/grails-best-practice-indexing-domain-class/6496 "2012-01-25T15:32:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_von\_Wendt\_](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@Christian\_von\_Wendt\_](https://discuss.elastic.co/u/Christian_von_Wendt_)\
**Post date:** [January 25, 2012, 3:32pm UTC](https://discuss.elastic.co/t/grails-best-practice-indexing-domain-class/6496/1 "2012-01-25T15:32:28Z")

</div>

Hi,

What is the best way to index all fields of a Grails domain class?

The naive way is to copy the domain class field by field, but it would  
be nice if you could just extract the properties of the document and  
store them directly - kind of like:

class DocumentService {  
...  
def store(Document doc) {  
def result = myClient.index {  
index "csj"  
type "doc"  
id "$doc.id"  
source {  
complex {  
doc.properties  
}  
}  
}

```
    log.info("Doc stored: $result")

}

```

}

Thanks,

Christian von Wendt-Jensen

---

<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:41am UTC](https://discuss.elastic.co/t/grails-best-practice-indexing-domain-class/6496/2 "2017-07-06T03:41:35Z")

</div>

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


