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))
)
$qwould be, it'll be easier for people to help.match, value:['AttachmentBody' => $q]), because each consecutive mention of the same key, overwrites the previous. Without knowing elasticsearch, my best guess is that you want something like:'match' => ['BugID' => $q, 'AttachmentTitle' => $q, 'AttachmentBody' => $q].