通配符查询没有 return 任何结果
wildcard query doesn't return any results
我正在尝试使用 query_string
、
通过通配符查询 Elasticsearch
我的查询是:
GET my_index/_search
{
"query": {
"nested": {
"path": "resources",
"query": {
"query_string": {
"query": "resources.data:*gotomeeting.com*"
}
}
}
}
}
查询没有 return 任何结果,即使我知道我的索引看起来像这样:
{
'main_url': 'some_url',
'resources': [
{
'actual_url': 'more_specific_url',
'data': 'general public.<a href="https://www3.gotomeeting.com/register/717380990" target="_blank">“FReSH:'
},
{
'actual_url': 'other_url', 'data':'more_data'
}
]
}
这是我的索引设置:
PUT my_index
{
"settings": {
"number_of_shards": 3,
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"char_filter": [
"my_char_filter"
]
}
},
"char_filter": {
"my_char_filter": {
"type": "html_strip"
}
}
}
},
"mappings": {
"_doc": {
"_source": {
"includes": [
"main_url"
],
"excludes": [
"resources.data",
"resources.actual_url"
]
},
"properties": {
"main_url": {
"type": "text", "norms": false,
"analyzer": "standard"
},
"resources": {
"type": "nested",
"properties": {
"actual_url": {
"type": "text", "norms": false,
"analyzer": "standard"
},
"data": {
"type": "text", "norms": false,
"analyzer": "my_analyzer"
}
}
}
}
}
}
}
我想知道这个过程中出了什么问题,以及如何使这个查询得到 return 个结果。
为什么不试试 Wildcard Query?它 returns 包含与通配符模式匹配的术语的文档。
我认为您的查询类似于:
GET my_index/_search
{
"query": {
"wildcard": {
"resources.data": {
"value": "*gotomeeting.com*",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
我建议您也检查一下 Rewrite documentation。
希望对您有所帮助! :D
如您所见,我在搜索 url 之前有“<\a”。问题是 html_strip
删除了 "<\a" 之后提到的所有内容(该标签定义了一个超链接)。
也就是说,显然 html_strip
的部分逻辑忽略了 urls.
可以简单地通过将 "a" 添加到 escaped_tags
来解决
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-htmlstrip-charfilter.html
我正在尝试使用 query_string
、
通过通配符查询 Elasticsearch
我的查询是:
GET my_index/_search
{
"query": {
"nested": {
"path": "resources",
"query": {
"query_string": {
"query": "resources.data:*gotomeeting.com*"
}
}
}
}
}
查询没有 return 任何结果,即使我知道我的索引看起来像这样:
{
'main_url': 'some_url',
'resources': [
{
'actual_url': 'more_specific_url',
'data': 'general public.<a href="https://www3.gotomeeting.com/register/717380990" target="_blank">“FReSH:'
},
{
'actual_url': 'other_url', 'data':'more_data'
}
]
}
这是我的索引设置:
PUT my_index
{
"settings": {
"number_of_shards": 3,
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"char_filter": [
"my_char_filter"
]
}
},
"char_filter": {
"my_char_filter": {
"type": "html_strip"
}
}
}
},
"mappings": {
"_doc": {
"_source": {
"includes": [
"main_url"
],
"excludes": [
"resources.data",
"resources.actual_url"
]
},
"properties": {
"main_url": {
"type": "text", "norms": false,
"analyzer": "standard"
},
"resources": {
"type": "nested",
"properties": {
"actual_url": {
"type": "text", "norms": false,
"analyzer": "standard"
},
"data": {
"type": "text", "norms": false,
"analyzer": "my_analyzer"
}
}
}
}
}
}
}
我想知道这个过程中出了什么问题,以及如何使这个查询得到 return 个结果。
为什么不试试 Wildcard Query?它 returns 包含与通配符模式匹配的术语的文档。
我认为您的查询类似于:
GET my_index/_search
{
"query": {
"wildcard": {
"resources.data": {
"value": "*gotomeeting.com*",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
我建议您也检查一下 Rewrite documentation。
希望对您有所帮助! :D
如您所见,我在搜索 url 之前有“<\a”。问题是 html_strip
删除了 "<\a" 之后提到的所有内容(该标签定义了一个超链接)。
也就是说,显然 html_strip
的部分逻辑忽略了 urls.
可以简单地通过将 "a" 添加到 escaped_tags
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-htmlstrip-charfilter.html