局部多场搜索弹性搜索

时间:2018-08-22 06:58:13

标签: javascript elasticsearch search indexing

我正在尝试设置一个匹配多个字段并满足以下要求的映射+查询:

我们的应用程序中有视频,我们为以下字段建立索引:localizedTitlelocalizedDescriptionlocalizedKeywords

示例视频:

{
  "_id": "5b7d02e023366c0d85cb05d8",
  "localizedTitle": [
    {
      "language": "en-GB",
      "value": "Test String"
    },
    {
      "language": "nl",
      "value": "Test String - In het nederlands"
    }
  ],
  "localizedDescription": [
    {
      "language": "en-GB",
      "value": "Test Description"
    }
  ],
  "localizedTags": [
    {
      "value": [
        "tag in nederlands"
      ],
      "language": "nl"
    }
  ]
}

要求是:

标题为“测试字符串”的视频

如果用户搜索:应返回

  • “测试”
  • “ Tes”
  • “ rin”
  • “ ing”
  • “ st st”

我们仅在映射字段中使用'type': 'text',所以那里没有什么特别的。

这是我们当前使用的查询:

  const query = {
    from: (page * perPage),
    size: perPage,
    query: {
      bool: {
        filter,
        must: {
          multi_match: {
            query: queryString,
            fields: [
              'localizedTitle.value',
              'localizedDescription.value',
              'localizedTags.value'
            ]
          }
        }
      }
    }
  }

运行测试套件,我们最终满足了一些要求,但部分单词搜索无法正常工作:

  GET /videos/search
    Search
      ✓ should respond with a result when searched for: Test (69ms)
      ✓ should respond with a result when searched for: Test Test (60ms)
      ✓ should respond with a result when searched for: test test (58ms)
      ✓ should respond with a result when searched for: Test st (54ms)
      ✓ should respond with a result when searched for: st Test (56ms)
      x) should respond with a result when searched for: Tes
      x) should respond with a result when searched for: rin
      x) should respond with a result when searched for: ing
      x) should respond with a result when searched for: st st

我们尝试过的事情:

  • 使用Fuzziness,设置为AUTOnumeric value (0 - 3)进行测试,但这给我们不一致的测试结果,似乎导致了与上述相同的结果集。
  • 使用正则表达式(但根据我们的研究,就性能而言,这不是可扩展的解决方案)

任何建议都值得欢迎

0 个答案:

没有答案