完成建议器以及弹性搜索中的附加条件

Nai*_*Kar 5 elasticsearch search-suggestion kibana elastic-stack elasticsearch-5

我有一个索引,可以返回不同语言的作业.

我需要根据单个文本搜索类似的作业到单一语言.所以说,我已经为英语设置了1作为LanguageId.我想搜索与帐户匹配的工作.因此,如果我写下面的查询,它会获取所有不同语言的作业.所以基本上"必须"查询没有任何影响.

GET jobs/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "languageid": "1"
          }
        }
      ]
    }
  },
  "suggest": {
    "suggestions": {
      "text": "acce",
      "completion": {
        "field": "jobs.suggest",
        "size": 30
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我的映射如下所示

   "mappings": {
"jobs": {
        "properties": {
          "@timestamp": {
            "type": "date"
          },
          "@version": {
            "type": "text"
          },
          "industytype": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "jobs": {
            "properties": {
              "suggest": {
                "type": "completion",
                "analyzer": "simple",
                "preserve_separators": true,
                "preserve_position_increments": true,
                "max_input_length": 50
              }
            }
          },
          "language": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "type": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "updateddate": {
            "type": "date"
          }
        }
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*kov 6

无法在查询时过滤掉建议,因为completion建议器使用FST - 在索引时构建的特殊内存数据结构:

Lucene 中的建议是通过从索引加载完成值然后构建 FST 在内存中构建的。这可能是一个缓慢的、资源密集型的过程。并且,一旦索引发生变化,就需要重建 FST。“实时搜索”是 Elasticsearch 的口头禅。返回过时的建议是不可接受的,索引更改时也不需要完全重建。我们现在不是在搜索时构建 FST,而是在索引时构建每个段的 FST。

因此,您所能做的就是为您的建议者添加上下文。上下文也在索引时与completion字段一起填充,因此可以在查询中的查询时使用suggest。另外,这篇文章可能对您有用。