elasticsearch - Elasticsearch 通配符使用
问题描述
问题
在弹性搜索上使用通配符运行查询时,不会返回预期结果。
要复制问题:
版本 5.5.1
创建索引
放置/示例测试/
{
"mappings": {
"Change": {
"properties": {
"id": {
"type": "keyword"
},
"searchProperties": {
"type": "nested",
"properties": {
"key": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "text",
"analyzer": "standard"
}
}
}
}
}
}
}
将文档添加到索引
发布 /example-test/Change/01_MEP_01
{
"id": "01_MEP_01",
"searchProperties": [
{
"key": "a.x",
"value": "You take the red pill you stay in Wonderland, and I show you how deep the rabbit hole goes"
}
]
}
观察索引中的文档
获取 /example-test/Change/_search
运行查询
POST /example-test/Change/_search
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "you ta",
"default_operator": "and",
"allow_leading_wildcard": true,
"analyze_wildcard": true,
"fields": [
"_all"
]
}
}
]
}
}
}
从这里开始,我将只指定查询的“查询”部分。我已经为几个例子运行了这个:
+-------------------+-------+
| Query | Found |
+-------------------+-------+
| you ta | false |
| you ta* | true |
| you take* | true |
| land | false |
| *land* | true |
| *land,* | false |
| *land, | false |
| wonderland | true |
| wonderland, | true |
| wonderlan*, | false |
| \\*wonderland,\\* | true |
+-------------------+-------+
注意 - 在最后一个示例中,通过阅读此处的文档https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string添加了通配符之前的反斜杠(可能是错误的) -query.html ) 声明的地方:
另一种选择是在查询字符串本身中提供通配符字段搜索(正确转义 * 符号)
这只是在查询中指定字段名称时吗?
问题
如果我想让我的用户搜索“land”并返回文档(因为它包含“wonderland”一词),我需要如何使用通配符来返回我的文档?
更多信息
看来逗号在这里引起了问题。这似乎很奇怪。查看运行生成的token:
发布 /example-test/_analyze
{
"analyzer": "standard",
"text": "You take the red pill you stay in Wonderland, and I show you how deep the rabbit hole goes"
}
我们可以看到“Wonderland”的结果是令牌“wonderland”。我的理解是查询将通过相同的分析器(https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html),所以应该产生相同的标记?看来不是这样的?
解决方案
推荐阅读
- ruby-on-rails - 忽略 ActiveRecord 属性的存在?
- android - 为什么 Gradle for Android 中包含 JavaScript 运行时?
- django - 相关模型 ID 会丢失在验证数据中,即使它存在于请求中
- python - 如何将列表列表原样导出到文件 Python
- regex - 有没有办法返回这个正则表达式的反义词?
- spotify - 如何使用 Sonos API 在 Sonos 上播放 Spotify 音乐
- python - 如何在 keras 批量更新期间缩放梯度?
- google-sheets - 如何在 Google 表格的数据透视表中按自定义顺序对列进行排序?
- firebase - 列出firebase数据库网络中的所有孩子
- ios - 将旋转视图控制器更改为单个通用视图控制器目标 c