EBernhardson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/332867 )

Change subject: Cleanup static analysis warnings with Elastica 5.0.0
......................................................................

Cleanup static analysis warnings with Elastica 5.0.0

* es5 removes search_type=count, instead prefering the _count api.
  Unfortunately we only use counting in multi-requests, which dont
  support the _count api. change them to use standard search requests
  with size=0, as we only care about total hits.
* Index::optimize() was renamed to Index::forcemerge(). No functional
  change here, it's strictly a name change
* Query::setFields() was changed to Query::setStoredFields(). This will
  create some annoyance for us during the transition period between
  2.x and 5.x, but can probably be worked around somehow.

Change-Id: Iec71b3fe5f0f00398ea3188c92201565da4a7ebd
---
M includes/BuildDocument/RedirectsAndIncomingLinks.php
M includes/Maintenance/Reindexer.php
M includes/OtherIndexes.php
M maintenance/dumpIndex.php
M maintenance/updateSuggesterIndex.php
5 files changed, 14 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/67/332867/1

diff --git a/includes/BuildDocument/RedirectsAndIncomingLinks.php 
b/includes/BuildDocument/RedirectsAndIncomingLinks.php
index 0c963f8..9328d63 100644
--- a/includes/BuildDocument/RedirectsAndIncomingLinks.php
+++ b/includes/BuildDocument/RedirectsAndIncomingLinks.php
@@ -182,12 +182,9 @@
                $search = new \Elastica\Search( $type->getIndex()->getClient() 
);
                $search->addIndex( $type->getIndex() );
                $search->addType( $type );
-               $search->setOption(
-                       \Elastica\Search::OPTION_SEARCH_TYPE,
-                       \Elastica\Search::OPTION_SEARCH_TYPE_COUNT
-               );
                $search->setQuery( $bool );
                $search->getQuery()->addParam( 'stats', 'link_count' );
+               $search->getQuery()->setSize( 0 );
 
                return $search;
        }
diff --git a/includes/Maintenance/Reindexer.php 
b/includes/Maintenance/Reindexer.php
index 259d0c9..16a8f21 100644
--- a/includes/Maintenance/Reindexer.php
+++ b/includes/Maintenance/Reindexer.php
@@ -229,7 +229,7 @@
                try {
                        // Reset the timeout just in case we lost it somewhere 
along the line
                        $this->setConnectionTimeout();
-                       $this->index->optimize( [ 'max_num_segments' => 5 ] );
+                       $this->index->forcemerge( [ 'max_num_segments' => 5 ] );
                        $this->output( "Done\n" );
                } catch ( HttpException $e ) {
                        if ( $e->getMessage() === 'Operation timed out' ) {
@@ -312,7 +312,7 @@
                $scrollId = null;
                try {
                        $query = new Query();
-                       $query->setFields( [ '_id', '_source' ] );
+                       $query->setStoredFields( [ '_id', '_source' ] );
                        if ( $filter ) {
                                $bool = new \Elastica\Query\BoolQuery();
                                $bool->addFilter( $filter );
diff --git a/includes/OtherIndexes.php b/includes/OtherIndexes.php
index 188c02b..fe97f74 100644
--- a/includes/OtherIndexes.php
+++ b/includes/OtherIndexes.php
@@ -100,7 +100,7 @@
                                $bool->addFilter( new \Elastica\Query\Term( [ 
'namespace' => $title->getNamespace() ] ) );
 
                                $query = new \Elastica\Query( $bool );
-                               $query->setFields( [] ); // We only need the 
_id so don't load the _source
+                               $query->setStoredFields( [] ); // We only need 
the _id so don't load the _source
                                $query->setSize( 1 );
 
                                $findIdsMultiSearch->addSearch( 
$type->createSearch( $query ) );
diff --git a/maintenance/dumpIndex.php b/maintenance/dumpIndex.php
index 0969b31..f80673c 100644
--- a/maintenance/dumpIndex.php
+++ b/maintenance/dumpIndex.php
@@ -122,7 +122,7 @@
                $limit = (int) $this->getOption( 'limit', 0 );
 
                $query = new Query();
-               $query->setFields( [ '_id', '_type', '_source' ] );
+               $query->setStoredFields( [ '_id', '_type', '_source' ] );
                if ( $this->hasOption( 'sourceFields' ) ) {
                        $sourceFields = explode( ',', $this->getOption( 
'sourceFields' ) );
                        $query->setSource( [ 'include' => $sourceFields ] );
diff --git a/maintenance/updateSuggesterIndex.php 
b/maintenance/updateSuggesterIndex.php
index 1b99aa2..136243e 100644
--- a/maintenance/updateSuggesterIndex.php
+++ b/maintenance/updateSuggesterIndex.php
@@ -152,9 +152,9 @@
                $this->addOption( 'baseName', 'What basename to use for all 
indexes, ' .
                        'defaults to wiki id', false, true );
                $this->addOption( 'indexChunkSize', 'Documents per shard to 
index in a batch.   ' .
-                   'Note when changing the number of shards that the old shard 
size is used, not the new ' .
-                   'one.  If you see many errors submitting documents in bulk 
but the automatic retry as ' .
-                   'singles works then lower this number.  Defaults to 100.', 
false, true );
+                       'Note when changing the number of shards that the old 
shard size is used, not the new ' .
+                       'one.  If you see many errors submitting documents in 
bulk but the automatic retry as ' .
+                       'singles works then lower this number.  Defaults to 
100.', false, true );
                $this->addOption( 'indexRetryAttempts', 'Number of times to 
back off and retry ' .
                        'per failure.  Note that failures are not common but if 
Elasticsearch is in the process ' .
                        'of moving a shard this can time out.  This will retry 
the attempt after some backoff ' .
@@ -426,7 +426,8 @@
 
                $query = new Elastica\Query();
                $query->setQuery( $bool );
-               $query->setFields( [ '_id' ] );
+               // TODO: _id should come back anyways, should this be empty 
array?
+               $query->setStoredFields( [ '_id' ] );
 
                $scrollOptions = [
                        'search_type' => 'scan',
@@ -499,13 +500,13 @@
 
        private function optimize() {
                $this->log("Optimizing index...");
-               $this->getIndex()->optimize( [ 'max_num_segments' => 1 ] );
+               $this->getIndex()->forcemerge( [ 'max_num_segments' => 1 ] );
                $this->output("ok.\n");
        }
 
        private function expungeDeletes() {
                $this->log("Purging deleted docs...");
-               $this->getIndex()->optimize( [ 'only_expunge_deletes' => true, 
'flush' => false ] );
+               $this->getIndex()->forcemerge( [ 'only_expunge_deletes' => 
true, 'flush' => false ] );
                $this->output("ok.\n");
        }
 
@@ -520,7 +521,7 @@
                $countIndices = [ Connection::CONTENT_INDEX_TYPE ];
 
                $query = new Query();
-               $query->setFields( [ '_id', '_type', '_source' ] );
+               $query->setStoredFields( [ '_id', '_type', '_source' ] );
                $query->setSource( [
                        'include' => $this->builder->getRequiredFields()
                ] );
@@ -541,7 +542,7 @@
                foreach ( $countIndices as $sourceIndexType ) {
                        $search = new \Elastica\Search( $this->getClient() );
                        $search->addIndex( $this->getConnection()->getIndex( 
$this->indexBaseName, $sourceIndexType ) );
-                       $search->setOption( 
\Elastica\Search::OPTION_SEARCH_TYPE, 
\Elastica\Search::OPTION_SEARCH_TYPE_COUNT );
+                       $search->getQuery()->setSize( 0 );
                        $mSearch->addSearch( $search );
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/332867
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec71b3fe5f0f00398ea3188c92201565da4a7ebd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: es5
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to