我必须使用grails对elasticsearch中的数据进行索引。
据我所知,只有域对象可以使用grails插件进行索引。是否有一个utilclass或服务来索引我不想存储在DB中的任意JSON数据?
到目前为止,我已经看到了以下索引方法,但它们似乎都需要域对象来进行索引。
// Index all searchable instances
elasticSearchService.index()
// Index a specific domain instance
MyDomain md = new MyDomain(value:'that')
md.save()
elasticSearchService.index(md)
// Index a collection of domain instances
def ds = [new MyDomain(value:'that'), new MyOtherDomain(name:'this'), new MyDomain(value:'thatagain')]
ds*.save()
elasticSearchService.index(ds)
// Index all instances of the specified domain class
elasticSearchService.index(MyDomain)
elasticSearchService.index(class:MyDomain)
elasticSearchService.index(MyDomain, MyOtherDomain)
elasticSearchService.index([MyDomain, MyOtherDomain])发布于 2014-01-20 18:26:21
可以使用Low level API来完成
下面的代码适用于我:
elasticSearchHelper.withElasticSearch { client ->
String json = "{" +
"\"user\":\"" + userName + "\"," +
"\"postDate\":\"2013-01-30\"," +
"\"message\":\"trying out Elastic Search\"" +
"}";
def response = client.prepareIndex("twitter", "tweet")
.setSource(json)
.execute()
.actionGet()
}https://stackoverflow.com/questions/18627715
复制相似问题