What's going on with my query?


(Hein Htet) #1

Failed to filters and retrieve it. Please kindly reply me i am new to elasticsearch
{"query":{"multi_match":{"query":"anchovy","fields":["title^4","description^3","shop_name^2","category.name"]}},"filter":{"and":[{"range" : {"prices" : {"retail": {"original": {"decimal": {"gte" : 20,"lt" : 40 } }} } }},{"term":{"shop_slug":"sharkys-dhammazedi.6326"}},{"term":{"shop_slug":"sharkys-pansodan.3752"}},{"geo_distance":{"distance":"20000miles","location":{"lat":16.7785335,"lon":96.1437569},"distance_type":"arc"}}]},"from":0,"size":52}


(Luiz Santos) #2

Hi @Hein_Htet,

You should use bool queries, take a look in this example:

GET _search
{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "anchovy",
            "fields": [
              "title^4",
              "description^3",
              "shop_name^2",
              "category.name"
            ]
          }
        }
      ],
      "filter": [
        {
          "range": {
            "prices": {
              "retail": {
                "original": {
                  "decimal": {
                    "gte": 20,
                    "lt": 40
                  }
                }
              }
            }
          }
        },
        {
          "term": {
            "shop_slug": "sharkys-dhammazedi.6326"
          }
        },
        {
          "term": {
            "shop_slug": "sharkys-pansodan.3752"
          }
        },
        {
          "geo_distance": {
            "distance": "20000miles",
            "location": {
              "lat": 16.7785335,
              "lon": 96.1437569
            },
            "distance_type": "arc"
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 52
}

Cheers,
LG


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.