Create query help

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

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...

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

 "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"
          }
        }
      }
    }
    
  }
}

}

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. 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.

{

 "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 ?

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:

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

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