We have configured ElasticSearch to create different index based on the date.
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open localbeta-logstash-2016.07.20 5 1 85636 0 27mb 27mb
yellow open .kibana 1 1 2 0 9.6kb 9.6kb
yellow open localbeta-logstash-2016.07.21 5 1 108346 0 37.7mb 37.7mb
yellow open localbeta-logstash-2016.07.22 5 1 58172 0 22.1mb 22.1mb
yellow open localbeta-logstash-2016.07.19 5 1 11535 0 3.6mb 3.6mb
Now we have to make a query for to fetch the logs against a particular field from all the indexes.
From the PHP-ElasticSearch, I understand that it is easy to query a particular index.
But how to query all the indexes at once?
You have to query for 'index' => '*'
* is a wildcard
You can use _all or empty string to refer to all indices: https://github.com/elastic/elasticsearch-php/blob/master/src/Elasticsearch/Client.php#L814
$params['index'] = (list) A comma-separated list of index names to search; use _all or empty string to perform the operation on all indices
Searching for different indexes works in the same way as searching for in a single index. You do not need to change anything in your query. You can use _all or like Vuldo mentioned '*' which is a wild card as the value for you index or just leave it empty and it will search all types in all indices.
You can take a look here for more details
In Kibana, you would search all docs with request below:
GET YOUR_INDEX_NAME/_search
{
"query": {
"match_all": {}
}
}
same for php, you create a same request body but with different syntax and would look like this:
[
"query" => [
"match_all" => new \stdClass()
]
]
Related
I have a small issue. I have a json file which I fetch data from.
When I print_r() the data, I see the field I want. But trying to call them, only 2 on 3 works, one seems to not be fetch-able.
Here the code, if someone have an idea about what's wrong:
Original JSON :
[
{
"ņame": "Xcoin",
"rate": "100.0000",
"status": "online"
}
]
The JSON with print_r()
Array
(
[ņame] => XCoin
[rate] => 100.0000
[status] => online
)
When I fetch individually each fields:
echo $coin['name']."<br>";
echo $coin['rate']."<br>";
echo $coin['status']."<br>";
The result of the previous code:
100.0000
online
Like if the name was not there! How's possible? I have others array and name fetch correctly, using same format.
Look at your array keys: ņ !== n so you're referencing an array index that doesn't exist.
I.e., that is not an n in the JSON you're getting, it's one of these characters.
(TIL this thing is called a cedilla.)
Look it's other character
ņame != name
I'm making a functional test with laravel / Phpunit
What I expect is having 2 rows with championship_id = 123
But the content of each row may vary.
I only know how to check if a row exists :
$this->seeInDatabase('championship_settings',
['championship_id' => $championship->id,
]);
but I don't know how to check that there is 2 rows corresponding to criteria
Any idea how should I do it???
U can use seeNumRecords($expectedNumber, $table, $criteria).
<?php
$this->seeNumRecords(2, 'championship_settings', ['championship_id' => $championship->id]);
?>
param int $expectedNumber Expected number
param string $table Table name
param array $criteria Search criteria [Optional]
See http://codeception.com/docs/modules/Db#seeNumRecords
So, here is the deal. I searched everywhere for the answer, but didn't find antyhing concrete ehough for my case, maybe i'm googling something wrong. Btw, i wanted phpmyadmin to be NOT in english, but it automatically changes back to cro... so... :/ hope you will understand enough to help me with solution...
Link to my table
TIP: I know how to get a solution through mysql, so you don't have to write those answers.
Here is the deal. This table is made by joining 2 other tables, because that was the only way to get all required data(that i must display) from one query (and that is relevant because later i will have to implement sort, which won't work otherwise).
I managed to pull out data which doesn't repeat itself with function, so this is what my solution looks by now:
1
tema1
opis1
sastanak.jpeg
2012-11-26 16:29:58
2012-11-26 17:30:00
2
tema2
opis2
sastanak.jpeg
2012-11-27 16:29:58
2012-11-29 18:30:00
3
tema3
opis3
sastanak.jpeg
2012-11-28 16:29:58
2012-11-28 17:05:00
4
tema4
opis4
sastanak.jpeg
2012-11-29 16:29:58
2013-11-29 21:42:00
and so on...
That's ok, but that is not all I need.
I'm still 2 steps away.
I need to count all id's, where current id is equal to previous. That means that solution would be:
5 (id_sastanka=1 appears 5 times in table)
5 (id_sastanka=2 appears 5 times),
6 (id_sastanka=3 appears 6 times),
6 (id_sastanka=4 appears 6 times) and so on.
I tried various combinations, but all give everything BUT correct result, so please help. I know the solution is in something simple, but I just can't seem to reach it. So this actually represents number of users who were invited to a meeting, by meeting's id.
I need to count all id's where status=1. I know how to do all of this with mysql, so that is not the question, I need the answer in php...
Solutions to this should be:
4 (four "1" in "status" where "id_sastanka"=1),
4 (four "1" in "status" where "id_sastanka"=2),
5 (five "1" in "status" where "id_sastanka"=3),
3 (three "1" in "status" where "id_sastanka"=4)....
this represents number of users who attended those meetings.
I'm a beginner, and I really need help with this, so I hope you won't bear a grudge.
I guess, that each row of your data represents as array. So, I'll write code for the following data structure:
$rows = array(
0 => array(
'id_sastanka' => 1,
'naziv' => 'tema1',
'opis' => 'opis1',
'slika' => 'sastanak.jpeg',
'posetak' => '<...>',
'zavrsetak' => '<...>',
'dnevny_red' => '<...>',
'id_korisnika' => '<...>',
'status' => '1'
),
1 => array(...),
2 => array(...),
...
);
$prev_id = null;
$prev_id_counter = array();
$ids_status_counter = array();
foreach($rows as $row) {
if ($prev_id == $row['id_sastanka']) {
$prev_id_counter[$row['id_sastanka']] = (isset($prev_id_counter[$row['id_sastanka']])) ? ++$prev_id_counter[$row['id_sastanka']] : 1;
}
$prev_id = $row['id_sastanka'];
if ($row['status'] == 1) {
$ids_status_counter[$row['id_sastanka']] = (isset($ids_status_counter[$row['id_sastanka']])) ? ++$ids_status_counetr[$row['id_sastanka']] : 1;
}
}
So, in array $prev_id_counter result for the first case and $ids_status_counter store result for the second one. Arrays have format ['id_sastanka'] => case counter
I'll explain this with mysql query.
select * from stock where home>away
home away
1 3
2 1
1 0
4 5
I just wanna make same query with mongodb. but I couldn't make this.
array('column' => array('$gt' => what should I write here?))
I need some help please for PHP usage.
You can not do this directly with a MongoDB query. Queries in MongoDB only allow comparisons with static values. However, there are a few options.
First of all, you can just store the result of the comparison whenever you update the values in each field, f.e., you can store it as:
home away gt
1 3 0
2 1 1
1 0 1
4 5 0
This is the simplest solution, and has the additional benefit that you can set an index on gt. Of course, it does mean more overhead when updating values. Doing this sort of pre-calculation is very similar to denormalisation. Denormalisation is something you will often have to do in NoSQL databases in order to make most of the system.
There is an alternative, but it wouldn't allow you to do an indexed search on >. You can use the aggregation framework in the following way:
db.so.aggregate( [
{ $project: {
'away' : 1,
'home': 1,
'better_at_home': { $cmp: [ '$home', '$away' ] }
} },
{ $match: { 'better_at_home': { $gt: 0 } } }
] );
In the first step, we use $cmp to compare home and away. In the second step ($match), we then filter out all the documents where the difference is less than or equal to 0.
The answer of the aggregation is:
{
"result" : [
{
"_id" : ObjectId("51ee7cfb812db9ff4412f12f"),
"home" : 2,
"away" : 1,
"better_at_home" : 1
},
{
"_id" : ObjectId("51ee7cff812db9ff4412f130"),
"home" : 1,
"away" : 0,
"better_at_home" : 1
}
],
"ok" : 1
}
Sadly, $gt cannot compare two fields.
What you can do for non time critical queries is to use $where;
> db.test.insert({home:5, away:3})
> db.test.insert({home:1, away:3})
> db.test.find({$where: 'this.home > this.away'})
{ "_id" : ObjectId("51ec576418fd21f745899945"), "home" : 5, "away" : 3 }
Your performance will be better though if you just store an additional "diff" field in the row object and search on that using $gt:0.
> db.test.insert({home:5, away:3, diff:2})
> db.test.insert({home:1, away:3, diff:-2})
> db.test.find({diff: {$gt:0}}, {_id:1,home:1,away:1})
{ "_id" : ObjectId("51ee982a6e4b3b34421de7bc"), "home" : 5, "away" : 3 }
You cannot use normal querying for this, however, never fear, the aggregation framework can help with the $cmp operator: http://docs.mongodb.org/manual/reference/aggregation/cmp/
db.collection.aggregate({$project:{c: {$cmp:['$col1','$col2']}}},{$match:{c:{$gt:0}}})
However, this being said it isn't very index friendly and is currently limited to 16meg of results.
edit
To take your edit into account:
$mongo->collection->aggregate(array(
array('$project'=>
array(
'c'=>array('$cmp'=>array('$col1','$col2'))
)
),
array('$match'=>array('c'=>array('$gt'=>0)))
))
I have created a light Model Manager for LDAP over PHP's API to ease object managements from Active Directory.
Everything runs fine but I have a problem when updating multi valued attributes even if I change all the values, the transaction fails with «Type or value exists» error and the attribute is not changed in the database.
The test case I am using is to change de multi valued "description" field for a user. If I add new values or change the whole array of values, the transaction always fail.
The part of the code is the following:
if (count($mod_attr) > 0)
{
$ret = #ldap_mod_replace($this->getHandler(), $dn, $mod_attr);
if ($ret === false)
{ $this->log(sprintf("LDAP ERROR '%s' -- Modifying {%s}.", ldap_error($this->getHandler()), print_r($mod_attr, true)), \SlapOM\LoggerInterface::LOGLEVEL_CRITICAL);
throw new LdapException(sprintf("Error while MODIFYING values <pre>%s</pre> in dn='%s'.", print_r($mod_attr, true), $dn), $this->getHandler(), $this->error);
}
$this->log(sprintf("Changing attribute {%s}.", join(', ', array_keys($mod_attr))));
}
The complete code can be found [here on github](https://github.com/chanmix51/SlapOM/blob/master/lib/SlapOM/Connection.php#L115 [github]).
The logs show the following lines:
2013-06-04 10:39:54 | => MODIFY dn='CN=HUBERT Gregoire,OU=...
2013-06-04 10:39:54 | => LDAP ERROR 'Type or value exists' -- Modifying {Array
(
[description] => Array
(
[0] => Description 2
[1] => Description 3
)
)}
Even if the preceding values were ["description" => ['Description 1']]. Is there something I am not getting or doing wrong ?
The answer is short: «Description is not a multi valued field». As usual, the error message was so confusing, it lead me to spend hours on the wrong problem.
In short: the LDAP error 20 «Type or value exists» can be either you are trying to insert twice the same values in a multi valued field or you are trying to insert several values in a single valued field.