When I upgrade SSL my elasticsearch has stopped working and do not know why?
$params = [
'index' => 'vf_dev',
'size' => $filter["limit"],
'from' => $filter["skip"],
'body' => [
'query' => [
'bool' =>
$search
]
]
];
My query is like above. My error is lilke below. What am I missing?
{"type":"x_content_parse_exception","reason":"[1:93] [bool] failed to parse field [must]"}],"type":"x_content_parse_exception","reason":"[1:93] [bool] failed to parse field [must]","caused_by":{"type":"illegal_state_exception","reason":"Can't get text on a START_ARRAY at 1:93
Tldr
I believe, your pattern for a boolean query is wrong.
As per the documentation you should have either:
filter
must
should
must_not
I believe it is missing.
Related
I'm facing an issue on the elastic search that it's not able to search if someone types wrong spelling. I have done some R & D about Soundex. Now I'm facing an issue to implement Soundex on elastic search. Please help me to do that, I've already installed Phonetic Anaalysis plugin on elastic search but how to configure the plugin with elastic search that will work with the search results.
'title' => [
'type' => 'text',
'analyzer' => $language . '_analyzer',
'index' => true,
'norms' => false,
'term_vector' => 'with_positions_offsets',
'fields' => [
'raw' => [
'type' => 'keyword',
'normalizer' => 'lowercase_normalizer',
'index' => true,
'norms' => false,
],
],
],
You need to create a custom analyzer using phonetic token filter and the apply this custom analyzer to your text field.
Alternatively, if you want to search with mistypes you can use fuzzy matches.
Elasticsearch: v7.2
Application: Laravel v.5.7
Hello and good day! I'm using Elasticsearch to make a report of my documents, I stumbled upon the need of presenting data fields that are nested in nature.
I have the following mappings, I have my index web with a field called ent:
Now I have the following query, using the aggs, my goal is to present the entities that have the MOST counts that can be found in my documents:
'aggs' => [
'ENT' => [
'nested' => [
'path' => 'ent'
],
'aggs' => [
'TOP_ENTITIES' => [
'terms' => [
'field' => 'ent.ent_count'
]
]
]
]
]
What I'm finding weird about this, is that when I'm targeting the ent.ent_count field, the buckets works perfectly fine, finding the distinct ent_count together with its respective doc_counts which portrays the total number of occurence of that ent_count:
BUT when I'm targeting the ent.ent_name field, it returns empty:
'aggs' => [
'ENT' => [
'nested' => [
'path' => 'ent'
],
'aggs' => [
'TOP_ENTITIES' => [
'terms' => [
'field' => 'ent.ent_name.keyword'
]
]
]
]
]
RESULTS TO
With non-nested fields, this works perfectly fine, am I doing something wrong with my query? because even the examples from the documentation shows the same scripts
There's no other way to solve this problem unless you change the mappings
So instead of letting the ent.ent_name nested field to be of text field, we have found out that short words in nested fields should be of KEYWORD type:
After changing the _mappings to keyword, everything worked perfectly fine
I updated my yii2 system from yii2-elasticsearch 2.0 to 2.1 and elasticsearch package from 2.2.1 to 6.2.1. In the old system I could mix $query->andFilterWhere and $query->query as follows (the search method is in a class derived from yii\elasticsearch\ActiveRecord):
public function search($params)
{
$query = self::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
$query->andFilterWhere([
'languageCode' => \Yii::$app->locale->languageCode,
]);
$queryPart = [];
if (!empty($this->term)) {
$queryPart['filtered']['query']['multi_match'] = [
// ES6: $queryPart['bool']['must']['multi_match'] = [
'query' => $this->term,
'operator' => 'and',
'type' => $this->getQueryType($this->term),
'fields' => [
'name_*',
'meta_description_*'
]
];
}
if (!empty($queryPart)) {
$query->query($queryPart);
}
return $dataProvider;
}
It worked with ES 2.2.1 without any problem, but now the andFilterWhere overwrites $query->query independently from the sequence. If one of the two parts is removed the other filter works perfectly, only together not.
Any idea?
You must use bool query and put all part of your query in one "query" object...
Something like this:
query => [
bool => [
must => [
multi_match => [
'query' => $this->term,
'operator' => 'and',
'type' => $this->getQueryType($this->term),
'fields' => [
'name_*',
'meta_description_*'
]
]
]
filter => [
'languageCode' => \Yii::$app->locale->languageCode
]
]
]
This problem seems to be bug, as confirmed by other users on github.
I'm writing a bot using Wit.ai and I'm having trouble understanding context. More specifically how/when to set it. As I've understood it you set the context by posting to the API at any point in time you see fit, for example when executing a function defined in a wit story. At least that's the approach I'm aiming for with the code below. Sadly it generates an error though so I wonder, am I trying to set the context in an incorrect way or is there something wrong with my Guzzle post?
private function storeUserName($entities) {
$witcall = $this->wit->post($this->wit_base_url.'/converse',
[
'form_params' => [
'username' => $entities->contact[0]->value
],
'query' => [
'v' => '1',
'session_id' => 'vk-'.$this->thread_id
],
'headers' => [
'Authorization' => 'Bearer '.env('WIT_TOKEN', false)
]
]
);
return [
'msg' => 'nice',
'type' => 'msg'
];
}
My error:
ClientException in RequestException.php line 111:
Client error: `POST https://api.wit.ai/converse?v=1&session_id=vk-1` resulted in a `400 Bad Request` response:
Unable to parse context in body
As it turned out using form_params was incorrect, changed to json and now it works fine. Like this:
$call = $this->wit->request('POST', 'converse', [
'json' => $this->context,
'query' => [
'v' => '1',
'session_id' => 'vk-'.$this->thread_id
]
]);
I would like to ask for some advices about Laravel Validation...
Let's say I've got an input named invoiceAddress[name] and in a controller I've got a rule
$rule = ['invoiceAddress.name' => 'required',];
or just a
$validator = \Validator::make($request->all(), [
'invoiceAddress.name' => 'required',
]);
now, inside custom validation language file validation.php, am I able to nest attributes somehow? like:
'required' => ':attribute is mandatory',
'attributes' => [
'invoiceAddress' => [
'name' => 'blahblah'
],
],
If I try to nest the attribute the way above, i get
ErrorException
mb_strtoupper() expects parameter 1 to be string, array given
because I am using a field (as above)
['name' => 'blahblah']
I am trying to get custom messages using the file and the :attribute directive (as mentioned in the code above).
I am basically trying to do this How to set custom attribute labels for nested inputs in Laravel but i get the mentioned error...
Thank you in advance...
A Note On Nested Attributes
If your HTTP request contains "nested" parameters, you may specify them in your validation rules using "dot" syntax:
$this->validate($request, [
'title' => 'required|unique:posts|max:255',
'author.name' => 'required',
'author.description' => 'required',
]);
Reference: https://laravel.com/docs/5.3/validation#quick-writing-the-validation-logic (A Note On Nested Attributes Section)