I want to check if the field exist in elasticsearch 1.3, the field is job_portal_id, please find my query as below
also i'm using Elasticsearch's php package for that
array:2 [
"query" => array:1 [
"filtered" => array:2 [
"query" => []
"filter" => array:2 [
"constant_score" => array:1 [
"exists" => array:1 [
"field" => "job_portal_id"
]
]
"term" => array:1 [
"location.country_code" => "ae"
]
]
....
When I run this query i get error exception in query
SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures
Related
I'm wondering if someone can help with the following please? Currently I have this array:
array:1 [
"blocks" => array:3 [
0 => array:1 [
"component" => "TextColumns"
]
1 => array:2 [
0 => array:1 [
"component" => "TextColumns"
]
1 => array:1 [
"component" => "TextColumns"
]
]
2 => array:1 [
"component" => "TextColumns"
]
]
]
What I want to achieve is a final array of the below:
array:1 [
"blocks" => array:3 [
0 => array:1 [
"component" => "TextColumns"
]
1 => array:1 [
"component" => "TextColumns"
]
2 => array:1 [
"component" => "TextColumns"
]
3 => array:1 [
"component" => "TextColumns"
]
]
]
If I use array_flatten or laravels ->flatten() I do not get the desired results as it flattens it too much:
array:1 [
"blocks" => array:3 [
0 => array:1 [
"component" => "TextColumns"
]
1 => array:2 [
0 => "TextColumns"
1 => "TextColumns"
]
2 => array:1 [
"component" => "TextColumns"
]
]
]
EDIT: Here is some source code for reference. I have header, content and footer methods. Both header and footer will always return a single array. Content however will be a multidimensional array as there could be multiple content blocks i.e.
protected static function header(): array
{
return [
'component' => 'TextColumns',
];
}
protected static function content(): array
{
return [
[
'component' => 'TextColumns',
],
[
'component' => 'TextColumns',
],
];
}
Then this is all merged together in the following array. Hence I need the content blocks to be flattened so that the blocks array just contains a simple array
dd([
'blocks' => [
static::header(),
static::content(),
static::footer(),
],
]);
Any help would be appreciated!
Thanks
I would like to transform a collection of object in laravel, but I can't figure it out how. I want to group the record by the type column, and set the grouped record under an array key value.
public function transformData()
{
$data = collect();
$matches = [ 'race', 'ethnicity'];
$attributes = Attribute::withTrashed()
->whereIn('type', $matches)
->get()
->groupBy('type');
$data->put(
$type, // to be the group key(like race)
[
'values' => $attributes->toArray(), // to be all the value with type race
]
);
dd(collect($data));
}
Here is what I'm getting:
Illuminate\Support\Collection^ {#2368
#items: array:1 [
"values" => array:2 [
"ethnicity" => array:2 [
0 => array:2 [
"id" => 1
"type" => "ethnicity"
]
1 => array:2 [
"id" => 2
"type" => "ethnicity"
]
]
"race" => array:2 [
0 => array:2 [
"id" => 6
"type" => "race"
]
1 => array:2 [
"id" => 7
"type" => "race"
]
]
]
]
#escapeWhenCastingToString: false
}
BUT I would like to return this instead:
Illuminate\Support\Collection^ {#2368
#items: array:1 [
"ethnicity" => array:2 [
"value" => array:2 [
0 => array:2 [
"id" => 1
"type" => "ethnicity"
]
1 => array:2 [
"id" => 2
"type" => "ethnicity"
]
]
]
"race" => array:2 [
"value" =>
0 => array:2 [
"id" => 6
"type" => "race"
]
1 => array:2 [
"id" => 7
"type" => "race"
]
]
]
#escapeWhenCastingToString: false
}
This is my search query. Here I am trying to search inside two different fields of two different index but it is giving result from one index only
array:2 [
"index" => "items-123-*,asso-456-*"
"body" => array:1 [
"query" => array:1 [
"bool" => array:1 [
"should" => array:2 [
0 => array:1 [
"match" => array:1 [
"title" => "Civics"
]
]
1 => array:1 [
"match" => array:1 [
"type" => "matchOf"
]
]
]
]
]
]
]
I tried below way but not working
array:1 [
"body" => array:1 [
"query" => array:1 [
"bool" => array:1 [
"should" => array:2 [
0 => array:2 [
"term" => array:1 [
"_index" => "items-123-123"
]
"match_phrase" => array:1 [
"title" => "Civics"
]
]
1 => array:2 [
"term" => array:1 [
"_index" => "cfassociations-345-*"
]
"match_phrase" => array:1 [
"type" => "matchOf"
]
]
]
]
]
]
]
Use alias to search for multiple index. For index items-123-*
POST _aliases
{
"actions": [
{
"add": {
"index": "items-123-*",
"alias": "my-new-index"
}
}
]
}
And for index asso-456-*
POST _aliases
{
"actions": [
{
"add": {
"index": "asso-456-*",
"alias": "my-new-index"
}
}
]
}
Now you can search by using the alias name my-new-index.
After loop made and using following array I can create a new array.
$data[$val['gid']][$val['rid']][$val['aid']][$teno][$userid]= array();
This results in the array below:
array:1 [
"FS OTHER" => array:1 [
"FS OTHER" => array:1 [
"FS OTHER" => array:1 [
"FS OTHER" => array:1 [
"D111" => []
]
]
]
]
]
I also have another array:
array:41 [
0 => array:2 [
"sid" => "D111"
"desc1" => "BANGKOK"
]
1 => array:2 [
"sid" => "D111"
"desc1" => "NONTHABURI"
]
2 => array:2 [
"sid" => "D112"
"desc1" => "PATHUM THANI"
]
Now I need to merge this array based on the 'sid' to get the following result:
array:1 [
"FS OTHER" => array:1 [
"FS OTHER" => array:1 [
"FS OTHER" => array:1 [
"FS OTHER" => array:1 [
"BANGKOK" => []
"NONTHABURI"=> []
]
]
]
]
]
You can prepare another structure of the second array
$new = [];
foreach ($arr2 as $x) {
$new[$x['sid']][$x['desc1']] = [];
}
// [D111 => [ BANGKOK => [], NONTHABURI => [] ],..
and then just create the 1st one by:
$data[$val['gid']][$val['rid']][$val['aid']][$teno][$userid]= $new[$userid];
$response['inserted_data'] =
array:3 [
0 => array:16 [
"name" => "Khv"
"emails" => array:1 [
0 => array:1 [
"email" => "demo#yahoo.com"
]
]
]
1 => array:18 [
"name" => "Aesha"
"emails" => array:1 [
0 => array:1 [
"email" => "test2#gmail.com"
]
]
]
How to get email values demo#yahoo.com and test2#gmail.com using pluck - php laravel and then from that emails need to get _id from database and update that records.
Try the below code :
Assuming your data look likes below array i.e $arrays.
$arrays=[
["name" => "Khv","emails" =>
[0 => ["email" => "demo1#yahoo.com"]
]
],
["name" => "asy", "emails" =>
[0 => ["email" => "demo2#yahoo.com"]
]
]
];
$emails=collect();
foreach ($arrays as $array) {
$emails->push($array['emails'][0]['email']);
}
dd($emails);
Note : You can't use pluck on array, it can be only used on collection.
You get the value from the pluck like below way.
User::all()->pluck('email');