Grails 如何使用ElasticSearch+;圣杯?
我使用Grails插件在MySQL上使用ElasticSearch。我在我的域类中映射了一个域列,如下所示:Grails 如何使用ElasticSearch+;圣杯?,grails,
elasticsearch,Grails,
elasticsearch,我使用Grails插件在MySQL上使用ElasticSearch。我在我的域类中映射了一个域列,如下所示: String updateHistoryJSON (...) static mapping = { updateHistoryJSON type: 'text', column: 'update_history' } 在MySQL中,这基本上映射到一个文本列,用于存储JSON内容 因此,在DB和ElasticSearch索引中,我有两个实例: -实例1的updateHistor
String updateHistoryJSON
(...)
static mapping = {
updateHistoryJSON type: 'text', column: 'update_history'
}
在MySQL中,这基本上映射到一个文本列,用于存储JSON内容
因此,在DB和ElasticSearch索引中,我有两个实例:
-实例1的updateHistoryJSON='{“zip”:null,“street”:null,“name”:null,“categories”:[],“city”:null}'
-实例2具有updateHistoryJSON='{}'
现在,我需要的是一个只返回实例2的ElasticSearch查询
我一直在使用Groovy DSL进行这样的闭包:
{
bool {
must_not = term(updateHistoryJSON: "{}")
minimum_should_match = 1
}
}
ElasticSearch似乎忽略了这一点,它不断地返回这两个实例
另一方面,如果我使用像“missing”:{“field”:“updateHistoryJSON”}这样的过滤器,它不会返回任何文档。“exists”{“field”:“updateHistoryJSON”}也是如此
知道我做错了什么吗?我仍然不确定问题出在哪里,但至少我找到了解决办法 由于基于updateHistoryJSON内容的搜索不起作用,我决定使用一个脚本来基于updateHistoryJSON内容大小进行搜索,这意味着,我不会查找具有非空JSON的文档,而是查找updateHistoryJSON大小大于2({}==大小2)的文档 我使用的闭包是这样的:
{script = {
script = "doc['updateHistoryJSON'].size() > 2"
}