首页 文章

Elasticsearch简单查询字符串查询与精确文本搜索

提问于
浏览
2

我有一个包含多个字段的文档 .

文献

  • 评论

  • 说明

  • Headers

我想搜索谷歌搜索,例如搜索

  • "blue car" -diesel gas

  • "blue car"混合动力

  • "blue car"橙色

  • 蓝色车橙色

当我使用“蓝色汽车”时,它必须是精确的值匹配而根本没有任何分析 . 它必须只找到没有词干等的确切短语

为此我得到了这样一个工作版本 - >

{
  "query": {
    "multi_match": {
      "query": "blue car",
      "fields": [
        "text",
        "message",
        "whatever"
      ],
      "type": "phrase"
    }
  }
}

虽然对于其他类型的搜索,如-diesel或混合 . 我正在考虑使用似乎支持这个的那个 .

{
   "query": {
        "simple_query_string": {
           "fields": [
            "text",
            "message",
            "whatever"],
           "default_operator": "and",
           "query": "-diesel +hybrid"
        }
     }
}

遗憾的是,即使我在查询中将文本放在引号中,简单的查询字符串查询也会使用分析器 .

你们有个想法我怎么能把这两者结合起来?我可以使用bool查询将它们组合在一起吗?

1 回答

  • 5

    这里's an example of the query 1074693 -diesel +hybrid'使用 bool query

    {
        "query": {
            "bool": {
                "must": [
                    {
                        "multi_match": {
                            "query": "blue car",
                            "fields": [
                                "text",
                                "message",
                                "whatever"
                            ],
                            "type": "phrase"
                        }
                    },
                    {
                        "multi_match": {
                            "query": "hybrid",
                            "fields": [
                                "text",
                                "message",
                                "whatever"
                            ]
                        }
                    }
                ],
                "must_not": {
                    "multi_match": {
                        "query": "diesel",
                        "fields": [
                            "text",
                            "message",
                            "whatever"
                        ]
                    }
                }
            }
        }
    }
    

相关问题