弹性搜索嵌套查询字符串?

时间:2018-09-19 08:03:20

标签: elasticsearch

我想使用通配符在2个不同的列中搜索2个值,但使用2个值不能按预期运行,但可以在单个query_string上正常运行

这适用于单列

{
  "query": {
    "query_string" : {
      "default_field" : "Phone",
      "query" : "*568072*"
    }
  }
}

我尝试将其扩展为与2个具有2个不同值的列一起使用。

{
    "query":
    {
        "bool":
        {
            "should": [
                {
                    "query_string":
                    {
                        "query": "*Chicago*",
                        "fields": ["Sources"]
                    },
                    "query_string":
                    {
                        "query": "*493*",
                        "fields": ["Phone"]
                    }


                }


            ]
        }
    }
}

我在哪里错了?

1 个答案:

答案 0 :(得分:0)

You have a mistake in your query. You have one big object inside should array, that has two same keys that does not make sense. Instead it should be array of objects like this:

{
  "query": {
    "bool": {
      "should": [
        { "query_string": { "query": "*Chicago*", "fields": ["Sources"] } },
        { "query_string": { "query": "*493*", "fields": ["Phone"] } }
      ]
    }
  }
}