Wildcard support in queries?
Final edit: ah okay you have you to use $query['wildcard'] to be able to use the wildcard character in queries. It should be documented somewhere :)
Okay I'm stuck with this. First of all any whitespace in the "wildcard" query breaks the whole thing.
Second, I believe this should work, but it only gives back results for the second wildcard:
$params['body'] = array(
'query' => array(
'filtered' => array(
'filter' => array(
'range' => array(
'@timestamp' => array(
'gt' => 'now-1h'
)
)
),
'query' => array(
'bool' => array(
'should' => array(
'wildcard' => array(
'file' => '*xyz1*'
),
'wildcard' => array(
'file' => '*xyz2*'
)
)
)
)
)
)
);
This can be related to mapping.
Can you add the mapping of the file field to this issue ?
Sure thing! Thanks for the quick answer.
"file":{
"type":"string",
"norms":{
"enabled":false
},
"fields":{
"raw":{
"type":"string",
"index":"not_analyzed",
"ignore_above":256
}
}
}
This doesn't seem to be a problem with the PHP library but with the query.
Your mapping is using a multi-field type. The standard file field is tokenized but the field.raw version is not. To resolve your problem of whitespace in your query, you should use the wildcard search with the not-analyzed version of your field : file.raw instead of just file.
...
'query' => array(
'bool' => array(
'should' => array(
'wildcard' => array(
'file.raw' => '*xyz1*'
),
'wildcard' => array(
'file.raw' => '*xyz2*'
)
)
)
)
...
For the other problem, I don't see anything wrong. Give another try after having switched to file.raw.
@MarkGavalda Did you get this sorted out? Need any more help?
Was also looking how the wildcard works.
From quick start
<?php
$searchParams['index'] = 'my_index';
$searchParams['type'] = 'my_type';
$searchParams['body']['query']['match']['testField'] = 'abc';
$retDoc = $client->search($searchParams);
Is it $searchParams['body']['query']['wildcard'] = true; ?
@harikt No, to use wildcards you have to use a query that supports them (the match query does not support wildcards). There is no "wildcard" parameter that is enabled.
Instead, you would use the wildcard query:
$searchParams['body']['query']['wildcard']['testField'] = 'abc*';
$results = $client->search($searchParams);
Or you could also use the query_string query:
$searchParams['body']['query']['query_string']['query'] = 'testField:abc*';
$results = $client->search($searchParams);
Thank you for your help @polyfractal .
Good if it is documented some where, so it will not be asked again by someone.