我已经编写了此python代码,首先在其中为内容指定data mapping
,然后在Elasticsearch中对内容进行搜索查询:
数据映射:
data_mapping = {
"settings": {
"analysis": {
"filter": {
"stop_words": {
"type": "stop",
"stopwords": "_english_"
},
"stemmer_stem": {
"type": "standard",
"language": "english"
},
"synonym": {
"type": "synonym",
"synonyms_path": "wn_s.pl"
}
},
"analyzer": {
"analyzer": {
"tokenizer": "standard",
"filter": [
"stop_words",
"stemmer_stem",
"synonym"
]
}
}
}
},
"mappings": {
str(index_name).lower(): {
"properties": {
"id": {
"type": "string",
"fields": {
"stemmed": {
"type": "string",
"analyzer": "analyzer"
}
}
},
"doc_q": {
"type": "array",
"fields": {
"stemmed": {
"type": "string",
"analyzer": "analyzer"
}
}
},
"doc_a": {
"type": "string",
"fields": {
"stemmed": {
"type": "string",
"analyzer": "analyzer"
}
}
},
"votes": {
"type": "integer",
"fields": {
"stemmed": {
"type": "integer",
"analyzer": "analyzer"
}
}
}
}
}
}
}
搜索查询:
query1 = {
"function_score": {
"query": {
"multi_match": {
"type": "phrase",
"query": question,
"fields": ["doc_q"]
}
},
"field_value_factor": {
"field": "votes",
"modifier": "log2p"
}
}
}
query2 = {
"function_score": {
"query": {
"multi_match": {
"type": "best_fields",
"query": question,
"fields": ["doc_q"]
}
},
"field_value_factor": {
"field": "votes",
"modifier": "log2p"
}
}
}
data = {
"query": {
"bool": {
"should": [
query1,
query2
]
}
}
}
response = es.search(index=str(index_name).lower(), body=data)
我已将wordnet
wn_s.pl
文件放在我的elasticsearch
安装目录的config目录中。当我执行搜索查询时,请说出enable
的同义词able
,它不会返回任何内容。不会出现错误,但看起来好像不是在wordnet
文件中搜索同义词
我的data mapping
或search query
中是否存在语法/逻辑错误?