Page MenuHomePhabricator

"Merge Duplicate Tasks" shows results in wrong order with ElasticSearch
Closed, ResolvedPublic

Description

I imagine this is an Elasticsearch thing. I've noticed that something the "Merge Duplicate Tasks" dialog shows search results in an unexpected order. For example, I typed the text T25070 into the search box and the results were:

  1. T250359 (which doesn't have anything to do with T25070)
  2. T25070

Event Timeline

joshuaspence raised the priority of this task from to Needs Triage.
joshuaspence updated the task description. (Show Details)
joshuaspence added a subscriber: joshuaspence.

I've made some small progress here.

Basically, I noticed that running ./bin/search init seems to fix it, except that I have to fake a conditional so that the index gets recreated. Basically, I applied the following diff:

diff --git a/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php b/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php
index 56a5b33..537a153 100644
--- a/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php
+++ b/src/applications/search/management/PhabricatorSearchManagementInitWorkflow.php
@@ -25,7 +25,7 @@ final class PhabricatorSearchManagementInitWorkflow
         "%s\n",
         pht('done.'));
       $work_done = true;
-    } else if (!$engine->indexIsSane()) {
+    } else if (!$engine->indexIsSane() || true) {
       $console->writeOut(
         '%s',
         pht('Index exists but is incorrect, fixing...'));
before.png (509×863 px, 27 KB)
after.png (510×861 px, 21 KB)
BeforeAfter

Comparing the mappings before and after (with curl 'http://localhost:9200/phabricator/_mappings?pretty=true'):

--- before	2015-08-17 17:20:10.124515704 +1000
+++ after	2015-08-17 17:20:12.404514790 +1000
@@ -101,8 +101,112 @@
               "corpus" : {
                 "type" : "string",
                 "analyzer" : "custom_trigrams"
+              },
+              "type" : {
+                "type" : "string"
               }
             }
+          },
+          "relationship" : {
+            "properties" : {
+              "auth" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              },
+              "clos" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "long"
+                  }
+                }
+              },
+              "open" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "long"
+                  }
+                }
+              },
+              "ownr" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "long"
+                  }
+                }
+              },
+              "proj" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              },
+              "subs" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              },
+              "unow" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              }
+            }
+          },
+          "title" : {
+            "type" : "string"
+          },
+          "url" : {
+            "type" : "string"
           }
         }
       },
@@ -131,8 +235,34 @@
               "corpus" : {
                 "type" : "string",
                 "analyzer" : "custom_trigrams"
+              },
+              "type" : {
+                "type" : "string"
+              }
+            }
+          },
+          "relationship" : {
+            "properties" : {
+              "clos" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "long"
+                  }
+                }
               }
             }
+          },
+          "title" : {
+            "type" : "string"
+          },
+          "url" : {
+            "type" : "string"
           }
         }
       },
@@ -146,8 +276,47 @@
               "corpus" : {
                 "type" : "string",
                 "analyzer" : "custom_trigrams"
+              },
+              "type" : {
+                "type" : "string"
+              }
+            }
+          },
+          "relationship" : {
+            "properties" : {
+              "auth" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              },
+              "repo" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
               }
             }
+          },
+          "title" : {
+            "type" : "string"
+          },
+          "url" : {
+            "type" : "string"
           }
         }
       },
@@ -215,8 +384,99 @@
               "corpus" : {
                 "type" : "string",
                 "analyzer" : "custom_trigrams"
+              },
+              "type" : {
+                "type" : "string"
+              }
+            }
+          },
+          "relationship" : {
+            "properties" : {
+              "auth" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              },
+              "clos" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "long"
+                  }
+                }
+              },
+              "open" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "long"
+                  }
+                }
+              },
+              "ownr" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              },
+              "proj" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
+              },
+              "subs" : {
+                "properties" : {
+                  "phid" : {
+                    "type" : "string"
+                  },
+                  "phidType" : {
+                    "type" : "string"
+                  },
+                  "when" : {
+                    "type" : "string"
+                  }
+                }
               }
             }
+          },
+          "title" : {
+            "type" : "string"
+          },
+          "url" : {
+            "type" : "string"
           }
         }
       },

I applied the following change locally. I'm not convinced that it is the most correct solution, but it seems to have worked for our install:

diff --git a/src/applications/search/engine/PhabricatorElasticSearchEngine.php b/src/applications/search/engine/PhabricatorElasticSearchEngine.php
index e991608..96f214c 100644
--- a/src/applications/search/engine/PhabricatorElasticSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorElasticSearchEngine.php
@@ -324,6 +324,7 @@ final class PhabricatorElasticSearchEngine extends PhabricatorSearchEngine {
       PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes());
     foreach ($types as $type) {
       // Use the custom trigram analyzer for the corpus of text
+      $data['mappings'][$type]['dynamic'] = false;
       $data['mappings'][$type]['properties']['field']['properties']['corpus'] =
         array('type' => 'string', 'analyzer' => 'custom_trigrams'
epriestley renamed this task from "Merge Duplicate Tasks" shows results in wrong order to "Merge Duplicate Tasks" shows results in wrong order with ElasticSearch.Dec 8 2016, 6:48 PM
epriestley added a subscriber: epriestley.

Presuming this is resolved since @20after4 couldn't reproduce it after T12450, feel free to follow up there or in a new task if you're still seeing issues.