带有查询输入的ElasticSearch查询

我在ElasticSearch中有一个数据索引

{
  "name":"john",
  "type":"main",
  "address":"26, pression road, next to maha maul, Atlanta, USA",
  "description":"i am from atlanta. i a need of help on elastic search. my name is john wosniak"
},
{
  "name":"shailesh",
  "type":"other",
  "address":"c-401, greenfield road, next to cyber city, mumbai, india",
  "description":"i am from mumbai. i dont need. my name shailesh"
},
{
  "name":"pratik",
  "type":"main",
  "address":"c-116, parmar society, john main road, andhari, India",
  "description":"i am from andhari. i a need of help on elastic search. my name is pratik doshi, i am good friend of john"
},...

我想使用一些高级查询进行搜索,以便在所有字段的其余部分中搜索“type”:“main”和“john”.

现在我正在使用查询

{
    "query_string" : {
        "fields" : ["name", "type","address", "description"],
        "query" : "main john*"
    }
}

根据我的要求,它没有给我想要的结果.

希望我已经解释清楚了.我在这里先向您的帮助表示感谢.

最佳答案 你看过 bool query吗?

您可以使用boosting获得所需的结果

 {
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "type": {
              "query": "main",
              "boost": 10
            }
          }
        },
        {
          "multi_match": {
            "query": "john",
            "fields": [
              "name",
              "address",
              "description"
            ]
          }
        }
      ]
    }
  }
}
点赞