简体   繁体   English

PHP Elasticsearch查询

[英]PHP Elasticsearch Query

I am trying to build a small web application to demo elasticsearch's capabilities, but I am running into an issue with my query. 我正在尝试构建一个小型Web应用程序以演示Elasticsearch的功能,但是我遇到了查询问题。 My goal is to search a string of keywords over all indexes and fields. 我的目标是在所有索引和字段中搜索一串关键字。 What I currently have seems to only search AttachmentBody , as when I search for BugID xyz or AttachmentTitle xyz nothing is displayed. 我目前所拥有的似乎只搜索AttachmentBody ,因为当我搜索BugID xyzAttachmentTitle xyz什么都没有显示。 I would greatly appreciate any help you may have to offer! 非常感谢您提供的任何帮助!

<?php

require_once 'es/esconnect.php';

if (isset($_GET['q'])){
    $q = $_GET['q'];
    $query = $Client->search([
        'body' =>[
            'query' =>[
                'bool' =>[
                    'should' =>[
                        'match' => ['BugID' => $q],
                        'match' => ['AttachmentTitle' => $q],
                        'match' => ['AttachmentBody' => $q]
                    ]
                ]
            ]
        ]
    ]);

    if($query['hits']['total'] >=1){
        $results = $query['hits']['hits'];
    }
}

?>

BugID: CSCzo56214 BugID:CSCzo56214

AttachmentTitle: 15624_note_21844 附件标题:15624_note_21844

AttachmentBody: this is a note AttachmentBody:这是一个注释


BugID: CSCzo56214 BugID:CSCzo56214

AttachmentTitle: 15624_description_21846 附件标题:15624_description_21846

AttachmentBody: this is a description AttachmentBody:这是一个描述


Working query: 工作查询:

    'body' =>[
        'query' =>[
            'bool' =>[
                'should' => array(
        array('match' => array('BugID' => $q)),
        array('match' => array('AttachmentTitle' => $q)),
        array('match' => array('AttachmentBody' => $q))
    )

Functioning query: 功能查询:

'body' => [
    'query' => [
        'bool' => [
            'should' => [
                ['match' => ['BugID'           => $q]],
                ['match' => ['AttachmentTitle' => $q]],
                ['match' => ['AttachmentBody'  => $q]]
            ]
        ]
    ]
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM