如何使用python在Elasticsearch映射中指定停用词

时间:2018-06-08 16:25:54

标签: python elasticsearch stop-words

我有这个python代码,我首先创建一个Elasticsearch映射,然后插入数据后我会搜索该数据:

# Create Data mapping
data_mapping = {
        "mappings": {
            (doc_type): {
                "properties": {
                    "data_id": {
                        "type": "string",
                        "fields": {
                            "stemmed": {
                                "type": "string",
                                "analyzer": "english"
                            }
                        }
                    },
                    "data":{
                        "type": "array",
                        "fields": {
                            "stemmed": {
                                "type": "string",
                                "analyzer": "english"
                            }
                        }
                    },
                    "resp": {
                        "type": "string",
                        "fields": {
                            "stemmed": {
                                "type": "string",
                                "analyzer": "english"
                            }
                        }
                    },
                    "update": {
                        "type": "integer",
                        "fields": {
                            "stemmed": {
                                "type": "integer",
                                "analyzer": "english"
                            }
                        }
                    }

                }
            }
        }
    }
#Search
data_search = {
        "query": {
            "function_score": {
                "query": {

                    "match": {
                        'data': question
                    }
                },
                "field_value_factor": {
                    "field": "update",
                    "modifier": "log2p"
                }
            }
        }
        }
response = es.search(index=doc_type, body=data_search)

现在我无法弄清楚在上面的代码中指定stopwords的位置和方式? This链接提供了使用stopwords的示例,但我无法将其与我的代码相关联。我是否需要在data mapping部分,搜索部分或两者中指定?我该如何指定呢?

任何示例帮助都将不胜感激!

更新:根据一些评论建议添加analysis部分或settings部分,但我不确定如何将其添加到{{1}我已在上面写过。

0 个答案:

没有答案