Wednesday, 2 December 2015

Elasticsearch: Java: match_all query


‘match_all’ query matches all documents.
{
         "match_all" : { }
}


GET /_search
{
  "query":{
    "match_all" : { }
  }
}

Following java snippet creates java query.

QueryBuilder builder = QueryBuilders.matchAllQuery();



Previous                                                 Next                                                 Home

Elasticsearch: Java: fuzzy query

Go through following link for details fuzzy query.

QueryBuilder builder = QueryBuilders.fuzzyQuery("text", "aara").boost(1.0f).prefixLength(0).maxExpansions(100).fuzziness(Fuzziness.TWO);

Above statement generates following fuzzy query.

{
  "fuzzy" : {
    "text" : {
      "value" : "aara",
      "boost" : 1.0,
      "fuzziness" : 2,
      "prefix_length" : 0,
      "max_expansions" : 100
    }
  }
}



Previous                                                 Next                                                 Home

Elasticsearch: Java: ids query

Return documents that have provided ids.

QueryBuilder builder = QueryBuilders.idsQuery(new String[] { "titles", "philosophy" }).ids(new String[] { "1", "4" });


Above query generates following json document.

{
  "ids" : {
    "types" : [ "titles", "philosophy" ],
    "values" : [ "1", "4" ]
  }
}


The type is optional and can be omitted, and can also accept an array of values.



Previous                                                 Next                                                 Home