I have for example following documents in elastic search:
{ make: 'honda',
model: 'civic 5-door'
year: '2011'
}
{ make: 'honda',
model: 'CIVIC TOURER 5-DOOR '
year: '2011'
}
{ make: 'honda',
model: 'JAZZ 5-DOOR'
year: '2012'
}
{ make: 'mazda',
model: 'some multi word name'
year: '2012'
}
I want to make a single search bar which could search across all the three fields. I tried the following query:
$query = 'some query string'
$results = $search->search([
'index' => 'cars',
'body' => [
"query" =>[
'multi_match' => [
"query" => $query,
"type" => "cross_fields",
"analyzer"=> "standard",
"fields" => ['model', 'make', 'year'] ]
]
]
]);
when i use search query like 'honda 2011', the query returns the result (it matches the query terms in 'make', and 'year'), but if i just type 'civic' (see the multi word field 'model'), it does not show any result. Why is the search into multi work field not working? Am i missing something? Please help.
My index mapping looks like the following:
$params = ['index' => 'cars'];
$params['body'] = [
'mappings' => [
'properties' => [
'body_type' => [
'type' => 'keyword'
],
'fuel_type' => [
'type' => 'keyword'
],
'engine_size' => [
'type' => 'short'
],
'make' => [
'type' => 'keyword'
],
'model' => [
'type' => 'keyword'
],
'dealership' => [
'type' => 'keyword'
],
'transmission' => [
'type' => 'keyword'
],
'colour' => [
'type' => 'keyword',
],
'location' => [
'type' => 'geo_point'
]
]
]
];