【问题标题】:Match on a text field with a token graph filter and keyword tokenizer - why order of query terms matters?使用标记图过滤器和关键字标记器匹配文本字段 - 为什么查询术语的顺序很重要?
【发布时间】:2020-03-27 20:14:35
【问题描述】:

我有一个由word_delimiter 过滤器填充的text 字段,使用keyword 标记器生成额外的标记,并且想搜索它们(match 操作),无论它们在查询字符串中的位置如何,例如

  1. 工作 - 找到文档:
GET test-position/_search
{
  "query": {
    "match": {
      "title.keywords": {
        "query": "yuio zxcv",
        "operator": "or"
      }}}}
  1. 不起作用 - 找不到文档,我真的不明白为什么?分析器为查询字符串生成相同的标记
GET test-position/_search
{
  "query": {
    "match": {
      "title.keywords": {
        "query": "zxcv yuio",
        "operator": "or"
      }}}}
  • 索引设置
PUT test-position
{
  "settings": {
    "number_of_shards": "1",
    "number_of_replicas": "0",
    "analysis": {
      "filter": {
        "word_delimiter_filter": {
          "type": "word_delimiter_graph",
          "catenate_words": "true",
          "catenate_numbers": "true",
          "catenate_all": "true",
          "preserve_original": "true",
          "generate_number_parts": "true"
        }},
      "analyzer": {
        "wordpart_analyzer": {
          "filter": [
            "word_delimiter_filter"
          ],
          "tokenizer": "keyword"
        }}}},
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "standard", 
        "fields": {
          "keywords": {
            "type": "text",
            "analyzer": "wordpart_analyzer"
          }}}}}}
  • 测试文档
PUT test-position/_bulk
{"index":{}}
{"title":"asdf qwer yuio zxcv"}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    有时候,彻底地阐述你的问题真的很有帮助:)

    我现在得到了答案:“魔术”参数是index_options。添加

    "index_options": "freqs"
    

    到字段映射解决了这个问题,因为默认行为是在索引时存储术语位置(或顺序)以及文档编号和术语频率。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 2015-02-17
      • 2010-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多