如何在创建索引时向 elasticsearch 模式添加过滤器和映射?

how to add filter and mappings to elasticsearch schema while creating the index?

我想在索引时使用同义词和停用词等过滤器以及弹性搜索模式中的映射类型。下面是我正在使用的 json。但是当我使用下面的 json 时,我能够获得映射但过滤器丢失了。可能是什么原因? (我使用的是 elasticsearch 6.2)

nlp_settings = {
"settings": {
"index" : {
    "number_of_shards": 1,
    "analysis": {
        "analyzer": {
            "synonym": {
                "tokenizer": "standard",
                "filter": ["synonym", "stop_words", "lowercase",
                           "stop_words_user", "synonym_user"]
            }
        },
        "filter": {
            "synonym": {
                "type": "synonym",
                "synonyms_path": "synonyms.txt"
            },
            "stop_words": {
                "type": "stop",
                "stopwords_path": "stopwords.txt"
            },
            "stop_words_user": {
                "type": "stop",
                "stopwords": "_none_"
            },
            "synonym_user": {
                "type": "synonym",
                "synonyms": default_synonym
            }
        }
    }
    }
    },
    "mappings": {
        "doc": {
          "properties": {
            "section":{"type": "text"}, 
            "document_name": {"type": "text"},
            "dir_path_info": {"type": "text"},
            "nlu_raw": {
                    "noun_list": {"type": "nested"},
                    "verb_list": {"type": "nested"},
                },
            "nlu": {
                    "noun": {"type": "nested"},
                    "verb": {"type": "nested"}    
                }
            }
        }
    }
}

当我将映射与过滤器一起使用时,当我从此 url http://localhost:9233/test/_settings

获取时,我得到以下 JSON
{
"test": {
    "settings": {
        "index": {
            "creation_date": "1523962921677",
            "number_of_shards": "5",
            "number_of_replicas": "1",
            "uuid": "FevdHGZjQm6ke2FgeNdnMQ",
            "version": {
                "created": "6020199"
            },
            "provided_name": "test"
        }
    }
}
}

然而,我真正想要的是

{
"test": {
    "settings": {
        "index": {
            "number_of_shards": "1",
            "provided_name": "test",
            "creation_date": "1523963029203",
            "analysis": {
                "filter": {
                    "synonym": {
                        "type": "synonym",
                        "synonyms_path": "synonyms.txt"
                    },
                    "synonym_user": {
                        "type": "synonym",
                        "synonyms": [
                            "a, a"
                        ]
                    },
                    "stop_words_user": {
                        "type": "stop",
                        "stopwords": [
                            "please",
                            "help"
                        ]
                    },
                    "stop_words": {
                        "type": "stop",
                        "stopwords_path": "stopwords.txt"
                    }
                },
                "analyzer": {
                    "synonym": {
                        "filter": [
                            "synonym",
                            "stop_words",
                            "lowercase",
                            "stop_words_user",
                            "synonym_user"
                        ],
                        "tokenizer": "standard"
                    }
                }
            },
            "number_of_replicas": "1",
            "uuid": "CiBBgngdR_aNHkY1m0EtXw",
            "version": {
                "created": "6020199"
            }
        }
    }
  }
}

当我从架构中删除映射时,我明白了。

settingsmappings 应该处于同一水平。所以:

{
  "settings": {
    "number_of_shards": 1,
    "analysis": {
      "analyzer": {
        "synonym": {
          "tokenizer": "standard",
          "filter": [
            "synonym",
            "stop_words",
            "lowercase",
            "stop_words_user",
            "synonym_user"
          ]
        }
      },
      "filter": {
        "synonym": {
          "type": "synonym",
          "synonyms_path": "synonyms.txt"
        },
        "stop_words": {
          "type": "stop",
          "stopwords_path": "stopwords.txt"
        },
        "stop_words_user": {
          "type": "stop",
          "stopwords": "_none_"
        },
        "synonym_user": {
          "type": "synonym",
          "synonyms": "default_synonym"
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "section": {
          "type": "text"
        },
        "document_name": {
          "type": "text"
        },
        "dir_path_info": {
          "type": "text"
        },
        "nlu_raw": {
          "properties": {
            "noun_list": {
              "type": "nested"
            },
            "verb_list": {
              "type": "nested"
            }
          }
        },
        "nlu": {
          "properties": {
            "noun": {
              "type": "nested"
            },
            "verb": {
              "type": "nested"
            }
          }
        }
      }
    }
  }
}