简体   繁体   English

Elasticsearch 关联精确匹配项

[英]Elasticsearch associating exact match terms

I have a search index of filenames containing over 100,000 entries that share about 500 unique variations of the main filename field.我有一个包含超过 100,000 个条目的文件名搜索索引,这些条目共享大约 500 个主filename段的独特变体。 I have recently made some modifications to certain filename values that are being generated from my data.我最近对从我的数据生成的某些文件名值进行了一些修改。 I was wondering if there is a way to link certain queries to return an exact match.我想知道是否有办法链接某些查询以返回完全匹配。 In the following query:在以下查询中:

"query": {
  "bool": {
    "must": [
      {
        "match": {
          "filename": "foo-bar"
        }
      }
    ],
  }
}

how would it be possible to modify the index and associate the results so that above query will also match results foo-bar-baz , but not foo-bar-foo or any other variation?如何修改索引并关联结果,以便上述查询也将匹配结果foo-bar-baz ,但不匹配foo-bar-foo或任何其他变体?

Thanks in advance for your help在此先感谢您的帮助

You can use a term query instead of a match query.您可以使用术语查询而不是匹配查询。 Perfect to use on a keyword: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html完美用于关键字: https : //www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html

Adding a working example with index data and search query.添加带有索引数据和搜索查询的工作示例。 (Using the default mapping) (使用默认映射)

Index Data:指数数据:

{
    "fileName": "foo-bar"
}
{
    "fileName": "foo-bar-baz"
}
{
    "fileName": "foo-bar-foo"
}

Search Query:搜索查询:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "fileName.keyword": "foo-bar" 
          }
        },
        {
          "match": {
            "fileName.keyword": "foo-bar-baz" 
          }
        }
      ]
    }
  }
}

Search Result:搜索结果:

"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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM