使用定义的分析器

使用定义的分析器

我正在尝试使用定义的分析器创建文本和关键字映射的索引,这是我到目前为止一直在尝试的操作:


{
    "settings" : {
        "number_of_shards" : 2,
        "number_of_replicas" : 1
    },

    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  ,
    "mappings": {
    "properties": {
  "question": {
    "type":"text",
    "fields": {
      "keyword": {
        "type": "keyword"
      },
     "normalize": {
      "type": "keyword",
      "normalizer": "my_normalizer"
    }

}
}
}
}
}


我已经试过了但是出错了:
"error": {
    "root_cause": [
        {
            "type": "parse_exception",
            "reason": "unknown key [analysis] for create index"
        }
    ],
    "type": "parse_exception",
    "reason": "unknown key [analysis] for create index"
},
"status": 400

}

问题是我需要在其中添加此映射的字段。
我正在AWS ES服务中尝试此操作。

最佳答案

很好的开始,您快到了!
analysis部分需要位于顶级settings部分内,如下所示:

{
  "settings": {
    "index": {
      "number_of_shards": 2,
      "number_of_replicas": 1
    },
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "question": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "normalize": {
            "type": "keyword",
            "normalizer": "my_normalizer"
          }
        }
      },
      "answer": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "normalize": {
            "type": "keyword",
            "normalizer": "my_normalizer"
          }
        }
      }
    }
  }
}

关于elasticsearch - 如何在Elasticsearch中使用定义的分析器和分片创建索引?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59988002/

10-16 12:29