在升级到Elastic-Search 5时替换ElasticSearch中的OR过滤查询

问题描述 投票:0回答:1

我正在尝试将Elastic-Search升级到版本5。以前,我使用的是Elastic-Search版本2。我很难将OR查询转换为bool [:should]查询。这是我的查询在ES-2中工作的样子。

 query: {:bool=>{ 
      :should=>[
          {:term=>{:user=>{:term=>70890}}},           
          {:term=>{:assignee=>{:term=>70890}}},
          {:term=>{:participant=>{:term=>70890}}}], 
      :minimum_number_should_match=>1,
      :filter=>[{:bool=> {:must_not=>{:exists=>{:field=>:date}}}},
                {:term=>{:deleted=>false}},                 
                {:or=>{:filters=>[
                    {:term=>{:user=>70890}},                     
                    {:term=>{:assignee=>70890}},
                    {:term=>{:private=>false}}
                ]}
                }
      ]
  }}

我要替换{{or => {:filters}}。我试过在:bool [:should]查询中移动这部分,但结果不正确。

    q[:bool][:should] << {term: {user: 70890}}
    q[:bool][:should] << {term: {assignee: 70890}}
    q[:bool][:should] << {term: {private: false}}
    q[:bool][:minimum_should_match] = 1

当我更改minimum_should_match = 2时,它会更改结果。我该如何解决?

elasticsearch elasticsearch-5
1个回答
0
投票

您应该阅读here。试试:

query: {:bool=>{ 
      :should=>[
          {:term=>{:user=>{:term=>70890}}},           
          {:term=>{:assignee=>{:term=>70890}}},
          {:term=>{:participant=>{:term=>70890}}}], 
      :minimum_number_should_match=>1,
      :filter=>[{:bool=> {:must_not=>{:exists=>{:field=>:date}}}},
                {:term=>{:deleted=>false}},                 
                {:bool=>{:filter=>[
                    {:term=>{:user=>70890}},                     
                    {:term=>{:assignee=>70890}},
                    {:term=>{:private=>false}}
                ]}
                }
      ]
  }}
© www.soinside.com 2019 - 2024. All rights reserved.