亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在彈性搜索PHP包中使用“And”運算符進行搜索

在彈性搜索PHP包中使用“And”運算符進行搜索

PHP
眼眸繁星 2022-08-19 15:35:09
我正在嘗試在php作曲家包的幫助下學習。我有一個名稱包含,字段。我想有基于上述字段的過濾器,它應該在運算符中。我目前的查詢代碼是:Elastic Searchindexmedia_datanits_accountnits_urlsession_idtimestampand$items = $this->elasticsearch->search([    'index' => $index_name,    'body'  => [        'query' => [            'filtered' => [                'filter' => [                    'and' => [                        ['match' => ['nits_account' => 'xyzABCD2190-aldsj']],  //API Key                        ['match' => ['nits_url' => 'google.com']],                    ]                ]            ]        ]    ]]);我的問題:我無法獲取數據。但是如果我做下面的代碼:$items = $this->elasticsearch->search([    'index' => $index_name,    'body'  => [        'query' => [             'bool' => [                'should' => [                    ['match' => ['nits_account' => $account] ],                    ['match' => ['nits_url' => $domain] ],                ],            ],         ]    ]]);我在運算符中獲取值,但需要在其中具有操作。orand我怎么能有不同的搜索操作與各自的字段,我的意思是我想有字段是完全匹配的,我想有喜歡/通配符操作,時間戳應該是可比的(大于/小于/在兩個日期之間)。nits_accountnits_url菲律賓比索彈性搜索elasticsearch-php
查看完整描述

1 回答

?
largeQ

TA貢獻2039條經驗 獲得超8個贊

試試這個:


$items = $this->elasticsearch->search([

    'index' => $index_name,

    'body'  => [

        'query' => [

             'bool' => [

                'must' => [

                    ['match' => ['nits_account' => $account] ],

                    ['match' => ['nits_url' => $domain] ]

                ],

            ], 

        ]

    ]

]);

您應該使用關鍵字,而不是關鍵字。 行為類似于 AND 操作,而作用類似于 OR 操作。mustshouldmustshould


請參閱此 https://stackoverflow.com/a/28768600/5430055


如果需要使用條件匹配,請使用如下內容:


"query": {

    "bool": {

      "must": [

        {

          "range": {

            "nits_url": {

              "gte": 1000,

              "lte": 10000

            }

          }

        },

        {

          "match": {

            "nits_account": "$account"

          }

        }

      ]

    }

  }


查看完整回答
反對 回復 2022-08-19
  • 1 回答
  • 0 關注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號