ElasticSearch query with input queries

I have a data index in 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"
},...

I want to perform a search using some preliminary inquiry that he was looking for "type":"main", and "john"in other fields.

now i am using query

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

it does not give me the desired result in accordance with my requirement.

I hope I have clearly explained. Thanks for the help in advance.
+4
source share
1 answer

Have you seen the bool query ?

You can achieve your desired results with boosting.

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

Source: https://habr.com/ru/post/1618017/


All Articles