我的 Elastic 搜索的映射如下所示:
{
"settings": {
"index": {
"number_of_shards": "5",
"number_of_replicas": "1"
}
},
"mappings": {
"node": {
"properties": {
"field1": {
"type": "keyword"
},
"field2": {
"type": "keyword"
},
"query": {
"properties": {
"regexp": {
"properties": {
"field1": {
"type": "keyword"
},
"field2": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
问题是:
我正在使用 elasticsearch_dsl Q() 形成 ES 查询。当我的查询包含任何复杂的正则表达式时,它在大多数情况下都可以正常工作。但如果它包含正则表达式字符“!”,则完全失败在里面。当搜索词包含“!”时,它不会给出任何结果在里面。
For eg:
1.) Q('regexp', field1 = "^[a-z]{3}.b.*")
(完美运作)
2.) Q('regexp', field1 = "^f04.*")
(完美运作)
3.)Q('regexp', field1 = "f00.*")
(完美运作)
4.) Q('regexp', field1 = "f04baz?")
(完美运作)
在以下情况下失败:
5.) Q('regexp', field1 = "f04((?!z).)*")
(失败,没有任何结果)
我尝试在字段中添加“analyzer”:“keyword”以及“type”:“keyword”,但在这种情况下没有任何效果。
在浏览器中,我尝试检查分析器:关键字在失败的情况下如何处理输入:
*
结果看起来不错:
{
"tokens": [
{
"token": "f04((?!z).)*",
"start_offset": 0,
"end_offset": 12,
"type": "word",
"position": 0
}
]
}
我正在运行我的查询,如下所示:
search_obj = Search(using = _conn, index = _index, doc_type = _type).query(Q('regexp', field1 = "f04baz?"))
count = search_obj.count()
response = search_obj[0:count].execute()
logger.debug("total nodes(hits):" + " " + str(response.hits.total))
请帮忙,这确实是一个烦人的问题,因为所有正则表达式字符在除 ! 之外的所有查询中都可以正常工作。
另外,我如何检查映射中当前应用了上述设置的分析器?