Skip to content

Commit

Permalink
Merge pull request #2968 from 10up/fix/distinct-meta-field-keys-es-5
Browse files Browse the repository at this point in the history
Account for difference on how mapping is returned on ES 5
  • Loading branch information
felipeelia authored Aug 29, 2022
2 parents c95713f + c769a88 commit 686a40b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions includes/classes/Indexable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,12 @@ public function get_distinct_meta_field_keys( $blog_id = null ) {
$mapping = $this->get_mapping();

try {
$meta_keys = array_keys( $mapping[ $this->get_index_name( $blog_id ) ]['mappings']['properties']['meta']['properties'] );
$meta_keys = array_values( $meta_keys );
if ( version_compare( Elasticsearch::factory()->get_elasticsearch_version(), '7.0', '<' ) ) {
$meta_fields = $mapping[ $this->get_index_name( $blog_id ) ]['mappings']['post']['properties']['meta']['properties'];
} else {
$meta_fields = $mapping[ $this->get_index_name( $blog_id ) ]['mappings']['properties']['meta']['properties'];
}
$meta_keys = array_values( array_keys( $meta_fields ) );
sort( $meta_keys );
} catch ( \Throwable $th ) {
return new \Exception( 'Meta fields not available.', 0 );
Expand Down

0 comments on commit 686a40b

Please sign in to comment.