Query with java api and two compare date


(Mohamed KHEMAKHEM) #1

Hi, we have index with two field firstDate and endDate and i need to execute request that match all documents that
endDate gte somedate1value and firstDAte lte somedate2value

How can ? write my query?

thanks


(David Pilato) #2

You can use a RangeFilter


(Mohamed KHEMAKHEM) #3

Bonjour David,
c'est ce que j'ai fait. ci-après mon code: Mais ça donne pas satisfaction

#################
FilterBuilder filter1 = FilterBuilders.rangeFilter("dateFin").gt(df.format(getDateDebutRecherche()));
FilterBuilder filter2 = FilterBuilders.rangeFilter("dateDebut").lt( df.format(getDateFinRecherche()));
client=ClientProvider.getTransportClient();

    SearchResponse response = client.prepareSearch(INDEX_NAME).setTypes(TYPE_NAME).
            setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),FilterBuilders.andFilter(filter1,filter2)))
            .execute()
            .actionGet(); 

#####################"


(system) #4