弹性反向查询

时间:2016-02-21 21:23:42

标签: search elasticsearch full-text-search

我使用弹性搜索进行经典查询LIKE"使用名称中的G4和manfucaturer中的LG搜索所有文档"。还行吧。但是如果我有很多文档和数据库包含大量搜索术语,我需要知道哪些文档与某些特定的多列术语相匹配。例如:

文件:

[
    {
     "id": 5787,
     "name": "Smartphone G4",
     "manufacturer": "LG",
     "description": "The revolutionary LG G4 design can only be described as forward thinking—with a classic touch."
    },
    {
     "id": 68779,
     "name": "Smartphone S6",
     "manufacturer": "Samsung",
     "description": "The Samsung Galaxy S6 is powerful to use and beautiful to behold."
    }
]

...

条款:

[
   {
     "id": "587",
     "name": "G4",
     "manufacturer": "LG",
     "description": "classic touch"
    },
    {
     "id": "364",
     "manufacturer": "Samsung",
     "description": "galaxy s6"
    }
]

...

结果:

{
  "587": [5787],
  "364": [68779]
}

OR:

{
  "5787": [587],
  "68779": [364]
}

我需要文档列表和对应它们的术语列表(或对应)。在少量术语中,应该可以逐个应用所有规则并保存匹配的文档。但我有数百万份文件和数千个术语。所以,不可能一个接一个地使用它们。是否有可能以另一种方式?

1 个答案:

答案 0 :(得分:0)

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html正是我想要的。它可以存储您的查询并针对文档执行它们。