简体   繁体   中英

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. 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. 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

AttachmentTitle: 15624_note_21844

AttachmentBody: this is a note


BugID: CSCzo56214

AttachmentTitle: 15624_description_21846

AttachmentBody: this is a description


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]]
            ]
        ]
    ]
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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