A
A
Alexander2017-10-24 17:20:53
elasticsearch
Alexander, 2017-10-24 17:20:53

How to build complex queries on ElasticSearch?

There are fields: https://prnt.sc/h1epxv
How to build a query that will allow me to select N number of values, where
WHERE `option 1` = "KEY1" AND `option2` < "KEY2" AND `option3` LIKE "KEY3"
then sort it all by,
ORDER BY `param4` > 100 DESC, param2 ASC

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kotofey, 2017-10-24
@indefpro

A lot depends on your mapping.
In general, if
`parameter 1` is a number or a string
`parameter 2` is a number
`parameter 3` is a string
then it will be like this

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "параметр 1": "KEY1"
          }
        },
        {
          "range": {
            "параметр 2": {
              "lt": "KEY2"
            }
          }
        },
        {
          "term": {
            "параметр 3": "KEY3"
          }
        }
      ],
      "must_not": [],
      "should": []
    }
  },
  "from": 0,
  "size": 10,
  "sort": [
    {
      "параметр4": "desc"
    },
    {
      "параметр2": "asc"
    }
  ],
  "aggs": {}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question