# Create query help

**URL:** https://discuss.elastic.co/t/create-query-help/141163
**Category:** Elasticsearch
**Created:** [July 23, 2018, 12:05pm UTC](https://discuss.elastic.co/t/create-query-help/141163 "2018-07-23T12:05:14Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![lebilien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lebilien/32/23755_2.png) [@lebilien](https://discuss.elastic.co/u/lebilien)
#### Post date: [July 23, 2018, 12:05pm UTC](https://discuss.elastic.co/t/create-query-help/141163/1 "2018-07-23T12:05:14Z")

</div>

hi i have the question about the query  
i have the information with the keyword with a date and a position  
i want all the keyword one a range date and where the position of the first date is superior of the position in the last date

do you have the idea ?

thanks

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 23, 2018, 12:41pm UTC](https://discuss.elastic.co/t/create-query-help/141163/2 "2018-07-23T12:41:48Z")

</div>

Wondering if some should clauses within bool query would help to increase the score when it matches several conditions + boost factor.

Otherwise `function_score` API might be the right choice...

---

<div class="post-metadata">

### Author: ![lebilien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lebilien/32/23755_2.png) [@lebilien](https://discuss.elastic.co/u/lebilien)
#### Post date: [July 23, 2018, 2:57pm UTC](https://discuss.elastic.co/t/create-query-help/141163/3 "2018-07-23T14:57:06Z")

</div>

ok but i have beginner in elastic and i have no idea to make this 🙂

---

<div class="post-metadata">

### Author: ![lebilien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lebilien/32/23755_2.png) [@lebilien](https://discuss.elastic.co/u/lebilien)
#### Post date: [July 23, 2018, 3:27pm UTC](https://discuss.elastic.co/t/create-query-help/141163/4 "2018-07-23T15:27:53Z")

</div>

```
 "aggs": {
"listekeyword": {
  "terms": {
    "field": "idkeyword.keyword",
    "size": 10
  },
  "aggs": {
    "listedate":{
      "date_histogram": {
        "field": "datecreation",
        "interval": "day",
        "order": [{"_key":"asc"}]
        
      },
      "aggs": {
        "position": {
          "min": {
            "field": "position"
          }
        }
      }
     
    },
    "listedatemax":{
      "date_histogram": {
        "field": "datecreation",
        "interval": "day",
        "order": [{
          "_key": "desc"
        }]
      }
      , "aggs": {
        "positionmax": {
          "min": {
            "field": "position"
          }
        }
      }
    }
    
  }
}

```

}

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 23, 2018, 6:11pm UTC](https://discuss.elastic.co/t/create-query-help/141163/5 "2018-07-23T18:11:35Z")

</div>

Sounds like you find a way to do it?

If not, feel free to provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

### Author: ![lebilien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lebilien/32/23755_2.png) [@lebilien](https://discuss.elastic.co/u/lebilien)
#### Post date: [July 24, 2018, 5:34am UTC](https://discuss.elastic.co/t/create-query-help/141163/6 "2018-07-24T05:34:44Z")

</div>

```
{

 "query": {
"bool": {
  "must": [
    {
      "match": {
        "idsite": 12
      }
    },
    {
      "match": {
        "device": "DESKTOP"
      }
    }
  ],
  "filter": {
      "range": {
        "datecreation": {
          "gte": "2017-05-01",
          "lte": "2017-07-31"
          
        }
        
      }
    }
}
},
"aggs": {
"listekeyword": {
  "terms": {
    "field": "idkeyword.keyword",
    "size": 10
  },
  "aggs": {
    "listedatemin":{
      "date_histogram": {
        "field": "datecreation",
        "interval": "day",
        "order": [{"_key":"asc"}]
        
      },
      "aggs": {
        "position": {
          "avg": {
            "field": "position"
          }
        }
      }
     
    },
    "listedatemax":{
      "date_histogram": {
        "field": "datecreation",
        "interval": "day",
        "order": [{
          "_key": "desc"
        }]
      }
      , "aggs": {
        "positionmax": {
          "avg": {
            "field": "position"
          }
        }
      }
    }
    
   }
  }
 }
}

```

i have this , but i want just one date in aggs listedatemin and listedateax but min\_doc\_count not working and it's possible to see a field with true ou false when listedatemin:avgposition \>listedatemax:avgposition ?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 24, 2018, 10:24am UTC](https://discuss.elastic.co/t/create-query-help/141163/7 "2018-07-24T10:24:00Z")

</div>

> A **full reproduction script** will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

So please share something we can use like:

```auto
DELETE index
PUT index/_doc/1
{
  "foo": "bar"
}
GET index/_search
{
  "query": {
    "match": {
      "foo": "bar"
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 21, 2018, 10:24am UTC](https://discuss.elastic.co/t/create-query-help/141163/8 "2018-08-21T10:24:06Z")

</div>

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