如何查询ES服务器以建议整个短语,但要考虑搜索短语中的每个单词?

时间:2018-11-01 20:47:04

标签: ubuntu elasticsearch search

Ubuntu 16.04
Elastic Search版本6.4.0

我有一个具有以下结构的文档:

{
  "items": {
    "mappings": {
      "item": {
        "properties": {
          "name": {
            "type": "text",
            "boost": 1.6
          },
          "color": {
            "type": "text",
            "boost": 1.4
          },
          "year": {
            "type": "text",
            "boost": 1.5
          },
          "condition": {
            "type": "text",
            "boost": 1.6
          },
          "description": {
            "type": "text",
            "boost": 1.1
          },
          "suggest": {
            "type": "completion",
            "analyzer": "standard",
            "preserve_separators": true,
            "preserve_position_increments": true,
            "max_input_length": 50,
            "contexts": [
              {
                "name": "name",
                "type": "category",
                "path": "name"
              },
              {
                "name": "color",
                "type": "category",
                "path": "color"
              },
              {
                "name": "year",
                "type": "category",
                "path": "year"
              }
            ]
          }
        }
      }
    }
  }
}  

如何查询ES服务器以建议整个短语,但要考虑到 搜索词中的每个单词?

例如,如果我搜索“ bike re”,则应该得到“ red 2014”和/或“ red 2016”之类的建议-当然可以。

这是我想出的(_search查询示例)。或者至少是我的想象。假设我输入“ bike re”。因此,在后端,我将标记所有字符串并将其小写,并搜索类似的内容:

{
  "suggest": {
    "suggest": {
      "prefix": "bike re",
      "completion": {
        "field": "suggest",
        "skip_duplicates": true,
        "size": 15,
        "contexts": {
          "name": [
            "bike",
            "re"
          ],
          "year": [
            "bike",
            "re"
          ]
        }
      }
    }
  }
}

但是,当然,这不会返回任何内容,因为上下文不匹配,并且没有“ bike re”建议字词, 而且,这意味着我必须为每个项目生成大量上下文(并建议输入),并且它们 必须是确切的字眼。还有其他办法吗?

使用模糊搜索是否可以更好地工作?

0 个答案:

没有答案