【问题标题】:Query nested fields with elasticsearch in grails在grails中使用elasticsearch查询嵌套字段
【发布时间】:2014-12-28 21:56:58
【问题描述】:

我是 elasticseach 的新手,在向我的查询添加过滤器时遇到了一些问题。

我的域类是这样的:

Class A {
    String name
    A_Status status

    static searchable =  {
        status component: true
    }
}

Class AImpl extends A {

}

Class A_Status {
    String name
    static searchable = { 
        root : false
        only = 'name'
    }
}

在我的控制器上,我正在做的查询是:

def res = elasticSearchService.search()
{
    bool {
        must {
            term("status.name": "ACTIVE")
        }
    }
 }

我尝试将searchable 字段更改为AImpl 或输入"searchable = true",但结果相同,查询始终为空,应该得到4 个结果。

我发现的另一件奇怪的事情是,进行 uri 搜索给了我预期的结果,但正文查询没有。

curl -XGET 'http://localhost:9200/com.sisconline.entities/_search?q=status.name=ACTIVE'

这有 4 次点击。

curl -XPOST 'http://localhost:9200/com.sisconline.entities/_search' -d '{
"query" : {
      "term":{ "status.name":"ACTIVE"}
      }
}'

这获得 0 次点击。

我正在使用Grails 2.3.4elasticsearch plugin 0.0.3.5

问候。

【问题讨论】:

    标签: grails elasticsearch grails-orm elasticsearch-plugin


    【解决方案1】:

    我终于设法通过这样做来解决问题:

    must { 
      nested { 
         path = "status" 
         query { 
             bool { 
                must { 
                   term("status.name": "active") } 
                } 
             } 
         } 
    } 
    

    希望对其他人有所帮助。

    【讨论】:

    • 您是否尝试使用您的域进行搜索?我有类似的映射(甚至几乎相同)并且面临的问题是,当我尝试通过 AImpl 搜索时,fe AImpl.search("${query}") 在 tomcat ERROR unmarshall.DomainClassUnmarshaller - Error unmarshalling Class AImpl with id ... Message: Property AImpl.status is not mapped as [component], but broken search hit found. 中出现异常另外,如果我尝试通过超类搜索,例如A.search("${query}") 我没有收到任何结果,似乎没有为 A 编制索引。
    • @JulyAntonicheva 从我目前看到的情况来看,框架索引子类而不是父类,因此如果您尝试按父类搜索,您将不会得到任何结果。事实上,我必须在所有子类中编写可搜索闭包,也许有一个我没有看到的配置参数。我没有使用我的域进行查询,因为我想要所有可能的结果。
    • @JulyAntonicheva 关于您遇到的错误,可能是您没有将属性指定为组件,在我的示例中是“状态组件:true”,或者您更改了映射并且没有t 清理索引以重建它。
    猜你喜欢
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 2016-08-23
    • 2021-02-11
    • 2020-10-10
    • 2017-12-03
    相关资源
    最近更新 更多