使用布尔查询(ElasticSearch)的nGram自动完成结果

时间:2018-01-29 11:46:37

标签: elasticsearch autocomplete

我已使用nGram-s实现了多字段部分自动完成功能,如以下博客文章中所示:https://qbox.io/blog/multi-field-partial-word-autocomplete-in-elasticsearch-using-ngrams1 在单个匹配查询的情况下,它非常有用。但是,在包含其他几个查询的布尔查询中使用相同的匹配查询时,它会失败。 在布尔查询的情况下,有没有办法获得与单个匹配查询相同的结果?

例如,下面的匹配查询按预期工作。它检索所有包含" shop"和" mi"。

{
     "query": {
         "match" : {
            "_all": {
                 "query": "shop mi",
                 "operator": "and"
            }
         }
     }
 }

这是一个示例文档,由上面的查询检索:

{
          "message" : "An error occurred while executing doInBackground()",
          "@version" : "1",
          "@timestamp" : "2018-01-23T10:22:46.689Z",
          "type" : "mytype",
          "app_name" : "name",
          "app_package" : "com.package",
          "exception" : "java.lang.RuntimeException",
          "is_handled" : false,
          "jailbroken" : false,
          "language_code" : "in",
          "orientation" : 0,
          "os_version" : "7.1.2",
          "phone_manufacturer" : "Xiaomi",
          "phone_model" : "Mi A1",
          "platform" : "android",
          "proc_info" : 8,
          "recommended_mgpx" : 5,
          "sd_card_available" : true,
          "stacktrace" : "java.lang.RuntimeException: An error occurred while executing doInBackground()\n\tat android.os.AsyncTask$3.done(AsyncTask.java:325)\n\tat java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)\n\tat java.util.concurrent.FutureTask.setException(FutureTask.java:223)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:242)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)\n\tat java.lang.Thread.run(Thread.java:761)\nCaused by: java.lang.IllegalArgumentException: cannot parse package /storage/emulated/0/app/.downloads/.shop/package\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:237)\n\t... 3 more\n",
          "total_disk_space" : 3071504384,
          "total_memory" : 3769253888,
          "user_id" : "81257074",
          "crash_case" : "at com.package.util.ae.a(ProGuard:43)"
        }

在字段" phone_manufacturer"和" phone_model"你可以看到" mi"必须在文档中。而田野" stacktrace"您可以在文档中看到" shop"(列为目录)以及" mi",以便匹配文档。

下面的布尔查询包含相同的匹配查询,但不检索任何文档。它导致0次点击。但是,它还应该检索所有那些包含" shop"和" mi",但是有#34; @ timestamp"的值指定范围内的字段。在上述文档的情况下,字段的值" @ timestamp"在所需的范围内。因此,它也应该在第二个查询的命中。

{
"query": {
  "bool" : {
    "must" : [
      {
        "range" : {
          "@timestamp" : {
            "from" : 1516881600000,
            "to" : 1516882500000,
            "include_lower" : true,
            "include_upper" : true,
            "format" : "epoch_millis",
            "boost" : 1.0
          }
        }
      }
    ],
    "filter" : [
      {
        "match" : {
          "_all" : {
            "query" : "shop mi",
            "operator" : "and",
            "boost" : 1.0
          }
        }
      }
    ],
    "boost" : 1.0
  }
 }
}

0 个答案:

没有答案