![](/img/trans.png)
[英]Elasticsearch match exact terms with spaces across different fields
[英]Elasticsearch associating exact match terms
我有一個包含超過 100,000 個條目的文件名搜索索引,這些條目共享大約 500 個主filename
段的獨特變體。 我最近對從我的數據生成的某些文件名值進行了一些修改。 我想知道是否有辦法鏈接某些查詢以返回完全匹配。 在以下查詢中:
"query": {
"bool": {
"must": [
{
"match": {
"filename": "foo-bar"
}
}
],
}
}
如何修改索引並關聯結果,以便上述查詢也將匹配結果foo-bar-baz
,但不匹配foo-bar-foo
或任何其他變體?
在此先感謝您的幫助
您可以使用術語查詢而不是匹配查詢。 完美用於關鍵字: https : //www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
添加帶有索引數據和搜索查詢的工作示例。 (使用默認映射)
指數數據:
{
"fileName": "foo-bar"
}
{
"fileName": "foo-bar-baz"
}
{
"fileName": "foo-bar-foo"
}
搜索查詢:
{
"query": {
"bool": {
"should": [
{
"match": {
"fileName.keyword": "foo-bar"
}
},
{
"match": {
"fileName.keyword": "foo-bar-baz"
}
}
]
}
}
}
搜索結果:
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_score": 0.9808291,
"_source": {
"fileName": "foo-bar"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "2",
"_score": 0.9808291,
"_source": {
"fileName": "foo-bar-baz"
}
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.