Hi,
For module elastic_connector_statistics, two quite usefull drupal_alter invocations are used:
// Alter the document, or add more fields.
drupal_alter('elasticsearch_connector_statistics_log_data', $doc, $client);
and
// Alter the mapping if necessary.
drupal_alter('elasticsearch_connector_statistics_get_mapping', $my_type_mapping);
For index elastic statistics (implemented in class SearchApiElasticsearchConnectorStats), similar statistics are missing. Attached patch adds ruch drupal_alters.
My use case context:
I'm using such alters to add date field (from some reason kibana refuses to handle timestamp correctly), and few additional fields (like geo_point, country and few other things).
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | drupal_alter-2633580-2.patch | 1.02 KB | visualfox |
| #2 | drupal_alter-2633580-1.patch | 1.1 KB | jsobiecki |
Comments
Comment #2
jsobiecki commentedComment #3
jsobiecki commentedComment #8
jsobiecki commentedComment #9
skek commented@harijari,
This seems like something we can add in the module itself instead of using alter hooks for it because it seems quite useful.
What do you think? Can you provide a patch by applying your changes directly on statistics module so I can review it?
BR,
N.Ignatov
Comment #10
jsobiecki commented@skek,
No problem, I can propose such patch. Currently we are testing solution internally, for one of our project, but if it will work I don't mind to share the patch, and extend solution to be something more general and usefull for others :) I'll let you know soon :)
Comment #11
visualfox commented@skek I have the same use case as harijari: Kibana doesn't recognize the unix timespan, and I need to add few more fields to the statistic (geo location, domain name, user status)
If I understand you correctly, you proposed to include the fix for Kibana directly in the module instead of offering an alter hook. That may works but only for adding support for Kibana this will not solve the issue with adding arbitrary field to the statistic. Also I have the feeling that the issue with Kibana is limited to Drupal 7. With Drupal 7 we are stuck with using Elasticsearch 1.7 and this version of Elasticsearch + Kibana doesn't support the unix timespan.
If needed I can provide a patch but adding support for Kibana on Drupal 7 is as simple as adding the following mapping:
$mapping['properties']['elastic_timestamp'] = array('type' => 'date');
and adding this record:
$doc['body']['elastic_timestamp'] = date('Y-m-d\TH:i:s');
I preferred to add a new date field 'elastic_timestamp' than modifying the already defined 'timestamp' one. As I am under the impression that this issue is limited to the Drupal 7 version, so internally we should continue to use the unix timespan.
Regardless I think the hooks alter make sense to add new fields to the statistic. Also this way the class 'SearchApiElasticsearchConnectorStats' will be consistent with the sub-module 'elastic_connector_statistics' which is already using these hooks.
Let me know if you need me to provide a patch for the hooks.
Comment #12
nwom commented@VisualFox: Please take a look at #2393885: ElasticSearch expects Milliseconds in Date Format. I got it working with the last patch for both Search API Views and Kibana. However, the only thing that does not work is Views Date filters. This way extra mapping is not required.
Comment #13
visualfox commented@NWOM that awesome! Sorry for my late reply I didn't get a notification from drupal.org
Comment #14
visualfox commented@NWOM I reviewed your patch - but I think the use case that @harijari and myself describe are a bit different: we also need a way to alter the mapping for search statistics in order to add new fields. Kibana timestamp support is part of the issue but doesn't represent the full use case.
The sub-module elastic_connector_statistics content two methods to alter the recorded statistics it seems logical to have equivalent methods into SearchApiElasticsearchConnectorStats
Comment #15
visualfox commentedRe-Roll patch
Comment #16
mparker17The 7.x-1.x branch has been unsupported for a while now, but it appears that this request is still outstanding as of 8.x-7.x, so I'm updating the version of this ticket to 8.x-7.x. Note that the cluster statistics page went away in 8.0.x, but the work to rebuild it is in #2320057: Build a report page based on the index statistics collected for the search, and I've updated that request to include the ability to alter the statistics before they are displayed.