带有查询输入的ElasticSearch查询

时间:2015-11-30 19:16:08

标签: 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*"
    }
}

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

希望我已经清楚地解释过了。感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

你看过bool query吗?

您可以使用boosting

获得所需的结果
 {
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "type": {
              "query": "main",
              "boost": 10
            }
          }
        },
        {
          "multi_match": {
            "query": "john",
            "fields": [
              "name",
              "address",
              "description"
            ]
          }
        }
      ]
    }
  }
}