首页 > 解决方案 > 弹性搜索查询

问题描述

我是弹性搜索的新手 我有这样的查询

select
    distinct count(distinct user0_.id) as col_0_0_ 
from
    user user0_ cross 
join
    account account1_ 
inner join
    user_detail userdetails_1 
        on user0_.user_detail_id=userdetails_1.id 
inner join
    level level3_ 
        on userdetails_1.level_id=level3_.id 
inner join
    credential credential4_ 
        on account1_.id=credential4_.account_id 
where
    user0_.status_id='published'
    and userdetails_1.program_type_id='spp'
    and level3_.active=1 
    and (
        userdetails_1.status_id not in  (
            'submitted-in-review' , 'expired' , 'rejected'
        )
    ) 
    and (
        userdetails_1.account_id=account1_.id 
        or userdetails_1.crm_record_id=account1_.global_partner_account 
        or userdetails_1.crm_record_id=account1_.top_parent
    ) 
    and (
        credential4_.type='Certification' 
        and credential4_.active=1 
        or credential4_.type='Professional Certification'
        or credential4_.type='Sales Certification'
    ) 
    and (
        credential4_.solution_category_id in (
            'test'
        )
    )

我需要将此查询转换为弹性搜索查询。

标签: javaspring-bootelasticsearch

解决方案


如果要查询索引,可以直接在开发工具中编写查询,如下所示:

POST _xpack/sql?format=txt
{
  "query":"DESCRIBE \"indice-name-*\""
}

POST _xpack/sql
{
  "query":"Select data1, data2 from \"indice-name-*\" where data1 = 'ABC' and ID = '11223333'"
}

推荐阅读