Permalink
Browse files

upgrade to elasticsearch 1.0.0.RC1 - Fix CountDsl to reflect

elasticsearch breaking changes.
roll back SimpleQueryString changes from 0.90.x
  • Loading branch information...
nicoo committed Jan 16, 2014
1 parent f968d0c commit 59ed55f3f732e46103ea26d42b4061b2f1b4c98e
Showing with 101 additions and 113 deletions.
  1. +1 −1 build.sbt
  2. +5 −2 src/main/scala/com/sksamuel/elastic4s/CountDsl.scala
  3. +2 −1 src/main/scala/com/sksamuel/elastic4s/DeleteDsl.scala
  4. +2 −2 src/main/scala/com/sksamuel/elastic4s/MoreLikeThisDsl.scala
  5. +1 −1 src/main/scala/com/sksamuel/elastic4s/SearchDsl.scala
  6. +1 −1 src/main/scala/com/sksamuel/elastic4s/ValidateDsl.scala
  7. +13 −28 src/main/scala/com/sksamuel/elastic4s/queries.scala
  8. +35 −36 src/test/resources/com/sksamuel/elastic4s/search_field.json
  9. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_filter_bool.json
  10. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_filter_geo_boundingbox.json
  11. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_filter_geo_distance.json
  12. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_filter_geo_polygon.json
  13. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_filter_geo_range.json
  14. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_function_score.json
  15. +0 −1 src/test/resources/com/sksamuel/elastic4s/search_fuzzy.json
  16. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_haschild_filter.json
  17. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_haschild_filter_query.json
  18. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_haschild_query.json
  19. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_hasparent_filter.json
  20. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_hasparent_filter_query.json
  21. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_hasparent_query.json
  22. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_id_filter.json
  23. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_missing_filter.json
  24. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_numeric_filter.json
  25. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_numeric_filter2.json
  26. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_numeric_filter3.json
  27. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_prefix_filter.json
  28. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_query_custom_score.json
  29. +2 −2 src/test/resources/com/sksamuel/elastic4s/search_query_dismax.json
  30. +2 −2 src/test/resources/com/sksamuel/elastic4s/search_query_filter.json
  31. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_query_filteredquery.json
  32. +0 −1 src/test/resources/com/sksamuel/elastic4s/search_query_flt.json
  33. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_range_filter.json
  34. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_regex_filter.json
  35. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_rescore.json
  36. +0 −1 src/test/resources/com/sksamuel/elastic4s/search_string.json
  37. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_term_filter.json
  38. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_terms_filter.json
  39. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_topchildren_query.json
  40. +1 −1 src/test/resources/com/sksamuel/elastic4s/search_type_filter.json
  41. +2 −0 src/test/scala/com/sksamuel/elastic4s/CountTest.scala
  42. +5 −5 src/test/scala/com/sksamuel/elastic4s/SearchDslTest.scala
  43. +3 −2 src/test/scala/com/sksamuel/elastic4s/UpdateTest.scala
View
@@ -46,7 +46,7 @@ libraryDependencies += "commons-io" % "commons-io" % "2.4"
libraryDependencies += "org.mockito" % "mockito-all" % "1.9.5" % "test"
-libraryDependencies += "org.elasticsearch" % "elasticsearch" % "1.0.0.Beta2"
+libraryDependencies += "org.elasticsearch" % "elasticsearch" % "1.0.0.RC1"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0.M6-SNAP36" % "test"
@@ -2,6 +2,7 @@ package com.sksamuel.elastic4s
import org.elasticsearch.action.count.{CountAction, CountRequestBuilder}
import org.elasticsearch.index.query.{QueryBuilder, QueryBuilders}
+import org.elasticsearch.action.support.QuerySourceBuilder
/** @author Stephen Samuel */
trait CountDsl {
@@ -20,10 +21,11 @@ trait CountDsl {
class CountDefinition(indexesTypes: IndexesTypes) extends RequestDefinition(CountAction.INSTANCE) {
- private val _builder = new CountRequestBuilder(null)
+ val _builder = new CountRequestBuilder(null)
.setIndices(indexesTypes.indexes: _*)
.setTypes(indexesTypes.types: _*)
.setQuery(QueryBuilders.matchAllQuery())
+
def build = _builder.request()
def routing(routing: String): CountDefinition = {
@@ -40,7 +42,8 @@ trait CountDsl {
def query(string: String): CountDefinition = query(new StringQueryDefinition(string))
def query(block: => QueryDefinition): CountDefinition = javaquery(block.builder)
def javaquery(block: => QueryBuilder): CountDefinition = {
- _builder.setQuery(block)
+ _builder.request.source(new QuerySourceBuilder().setQuery(block))
+ //_builder.setQuery(block)
this
}
@@ -3,6 +3,7 @@ package com.sksamuel.elastic4s
import org.elasticsearch.client.Requests
import org.elasticsearch.action.deletebyquery.DeleteByQueryAction
import org.elasticsearch.action.delete.DeleteAction
+import org.elasticsearch.action.support.QuerySourceBuilder
/** @author Stephen Samuel */
trait DeleteDsl extends QueryDsl with IndexesTypesDsl {
@@ -73,7 +74,7 @@ trait DeleteDsl extends QueryDsl with IndexesTypesDsl {
private val builder = Requests.deleteByQueryRequest(indexesTypes.indexes: _*)
.types(indexesTypes.types: _*)
- .query(q.builder)
+ .source(new QuerySourceBuilder().setQuery(q.builder))
def types(types: String*): DeleteByQueryDefinition = {
builder.types(types.toSeq: _*)
@@ -43,11 +43,11 @@ trait MoreLikeThisDsl {
this
}
def maxWordLen(maxWordLen: Int) = {
- _builder.maxWordLen(maxWordLen)
+ _builder.maxWordLength(maxWordLen)
this
}
def minWordLen(minWordLen: Int) = {
- _builder.minWordLen(minWordLen)
+ _builder.minWordLength(minWordLen)
this
}
def boostTerms(boostTerms: Double) = {
@@ -96,7 +96,7 @@ trait SearchDsl
}
def filter(block: => FilterDefinition): SearchDefinition = {
- _builder.setFilter(block.builder)
+ _builder.setPostFilter(block.builder)
this
}
@@ -26,7 +26,7 @@ trait ValidateDsl extends QueryDsl {
*/
def query(string: String): ValidateDefinition = {
val q = new StringQueryDefinition(string)
- _builder.setQuery(q.builder.buildAsBytes)
+ _builder.setQuery(q.builder)
this
}
@@ -10,7 +10,7 @@ import scala.Some
trait QueryDsl {
- implicit def string2query(string: String) = new StringQueryDefinition(string)
+ implicit def string2query(string: String) = new SimpleStringQueryDefinition(string)
implicit def tuple2query(kv: (String, String)) = new TermQueryDefinition(kv._1, kv._2)
def query = this
@@ -44,10 +44,10 @@ trait QueryDsl {
def dismax = new DisMaxDefinition
- def field(tuple: (String, Any)): FieldQueryDefinition = fieldQuery(tuple)
- def field(field: String, value: Any): FieldQueryDefinition = fieldQuery(field, value)
- def fieldQuery(tuple: (String, Any)): FieldQueryDefinition = fieldQuery(tuple._1, tuple._2)
- def fieldQuery(field: String, value: Any): FieldQueryDefinition = new FieldQueryDefinition(field, value)
+ def field(tuple: (String, String)): FieldQueryDefinition = fieldQuery(tuple)
+ def field(field: String, value: String): FieldQueryDefinition = fieldQuery(field, value)
+ def fieldQuery(tuple: (String, String)): FieldQueryDefinition = fieldQuery(tuple._1, tuple._2)
+ def fieldQuery(field: String, value: String): FieldQueryDefinition = new FieldQueryDefinition(field, value)
def fuzzylikethis: FuzzyLikeThisDefinitionExpectsText = flt
def flt: FuzzyLikeThisDefinitionExpectsText = new FuzzyLikeThisDefinitionExpectsText
@@ -120,7 +120,7 @@ trait QueryDsl {
def prefixQuery(tuple: (String, Any)): PrefixQueryDefinition = prefixQuery(tuple._1, tuple._2)
def prefixQuery(field: String, value: Any): PrefixQueryDefinition = new PrefixQueryDefinition(field, value)
-// def simpleStringQuery(q: String): SimpleStringQueryDefinition = new SimpleStringQueryDefinition(q)
+ def simpleStringQuery(q: String): SimpleStringQueryDefinition = new SimpleStringQueryDefinition(q)
def stringQuery(q: String) = new StringQueryDefinition(q)
def spanOrQuery = new SpanOrQueryDefinition
@@ -263,10 +263,7 @@ class MultiMatchQueryDefinition(text: String)
class FuzzyDefinition(name: String, value: Any) extends QueryDefinition with DefinitionAttributePrefixLength {
val builder = QueryBuilders.fuzzyQuery(name, value.toString)
val _builder = builder
- def minSimilarity(minSimilarity: Double) = {
- builder.minSimilarity(minSimilarity.toString)
- this
- }
+
def maxExpansions(maxExpansions: Int) = {
builder.maxExpansions(maxExpansions)
this
@@ -363,10 +360,6 @@ class FuzzyLikeThisDefinition(text: String, fields: Iterable[String])
builder.maxQueryTerms(b)
this
}
- def minSimilarity(b: Double): FuzzyLikeThisDefinition = {
- builder.minSimilarity(b.toFloat)
- this
- }
}
class CommonQueryDefinition(name: String, text: String) extends QueryDefinition {
@@ -512,11 +505,12 @@ class WildcardQueryDefinition(field: String, query: Any)
}
}
-class FieldQueryDefinition(field: String, query: Any)
+class FieldQueryDefinition(field: String, query: String)
extends QueryDefinition
with DefinitionAttributeRewrite {
- val builder = QueryBuilders.fieldQuery(field, query)
+ val builder = QueryBuilders.queryString(query).defaultField(field)
val _builder = builder
+
def boost(boost: Double) = {
builder.boost(boost.toFloat)
this
@@ -536,11 +530,6 @@ class FieldQueryDefinition(field: String, query: Any)
this
}
- def fuzzyMinSim(fuzzyMinSim: Double) = {
- builder.fuzzyMinSim(fuzzyMinSim.toFloat)
- this
- }
-
def analyzer(analyzer: Analyzer) = {
builder.analyzer(analyzer.name)
this
@@ -880,8 +869,9 @@ class MatchPhraseDefinition(field: String, value: Any)
}
}
-/*
+
class SimpleStringQueryDefinition(query: String) extends QueryDefinition {
+ val builder = QueryBuilders.simpleQueryString(query)
def defaultOperator(d: SimpleQueryStringBuilder.Operator): SimpleStringQueryDefinition = {
builder.defaultOperator(d)
@@ -902,7 +892,7 @@ class SimpleStringQueryDefinition(query: String) extends QueryDefinition {
builder.field(name, boost.toFloat)
this
}
-} */
+}
class StringQueryDefinition(query: String) extends QueryDefinition with DefinitionAttributeRewrite {
@@ -942,11 +932,6 @@ class StringQueryDefinition(query: String) extends QueryDefinition with Definiti
this
}
- def fuzzyMinSim(fuzzyMinSim: Double): StringQueryDefinition = {
- builder.fuzzyMinSim(fuzzyMinSim.toFloat)
- this
- }
-
def anaylyzer(analyzer: Analyzer): StringQueryDefinition = {
builder.analyzer(analyzer.name)
this
@@ -1,38 +1,37 @@
-{"size": 5, "query": {
+{
+ "size": 5,
+ "query": {
"bool": {
- "must": [
- {
- "field": {
- "name": {
- "query": "coldplay",
- "allow_leading_wildcard": true,
- "boost": 5.0,
- "fuzzy_prefix_length": 5,
- "phrase_slop": 9,
- "analyze_wildcard": false
- }
- }
- },
- {
- "field": {
- "status": {
- "query": "awesome",
- "analyzer": "pattern",
- "auto_generate_phrase_queries": true,
- "enable_position_increments": true
- }
- }
- },
- {
- "field": {
- "location": {
- "query": "oxford",
- "fuzzy_min_sim": 0.5,
- "fuzzy_max_expansions": 7,
- "rewrite": "rewrite"
- }
- }
- }
- ]
+ "must": [
+ {
+ "query_string": {
+ "query": "coldplay",
+ "default_field": "name",
+ "allow_leading_wildcard": true,
+ "boost": 5.0,
+ "fuzzy_prefix_length": 5,
+ "phrase_slop": 9,
+ "analyze_wildcard": false
+ }
+ },
+ {
+ "query_string": {
+ "query": "awesome",
+ "default_field": "status",
+ "analyzer": "pattern",
+ "auto_generate_phrase_queries": true,
+ "enable_position_increments": true
+ }
+ },
+ {
+ "query_string": {
+ "query": "oxford",
+ "default_field": "location",
+ "fuzzy_max_expansions": 7,
+ "rewrite": "rewrite"
+ }
+ }
+ ]
}
-}}
+ }
+}
@@ -1,5 +1,5 @@
{
- "filter": {
+ "post_filter": {
"bool": {
"must": {
"term": {
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"geo_bbox": {
"box": {
"top_left": [56.5, 40.6],
@@ -1,5 +1,5 @@
{
- "filter": {
+ "post_filter": {
"bool": {
"must_not": {
"geo_distance": {
@@ -1,5 +1,5 @@
{
- "filter": {
+ "post_filter": {
"geo_polygon": {
"distance": {
"points": [
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"geo_distance_range": {
"postcode": "hash123",
"from": "560",
@@ -2,7 +2,7 @@
"query":{
"function_score":{
"query":{
- "query_string":{
+ "simple_query_string":{
"query":"coldplay"
}
},
@@ -4,7 +4,6 @@
"value": "will",
"boost": 4.0,
"transpositions": true,
- "min_similarity": "2.2",
"prefix_length": 10,
"max_expansions": 10
}
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"has_child": {
"filter": {
"term": {
@@ -1,5 +1,5 @@
{
- "filter": {
+ "post_filter": {
"has_child": {
"query": {
"term": {
@@ -1,7 +1,7 @@
{"size": 5, "query": {
"has_child": {
"query": {
- "query_string": {
+ "simple_query_string": {
"query": "coldplay"
}
},
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"has_parent": {
"filter": {
"term": {
@@ -1 +1 @@
-{"filter":{"has_parent":{"query":{"term":{"name":"chris"}},"parent_type":"singer"}}}
+{"post_filter":{"has_parent":{"query":{"term":{"name":"chris"}},"parent_type":"singer"}}}
@@ -1,7 +1,7 @@
{"size": 5, "query": {
"has_parent": {
"query": {
- "query_string": {
+ "simple_query_string": {
"query": "coldplay"
}
},
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"ids": {
"types": [],
"values": ["a", "b", "c", "q", "r"],
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"missing": {
"field": "producer",
"null_value": true,
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"numeric_range": {
"years": {
"from": 1900,
@@ -1,4 +1,4 @@
-{"filter": {
+{"post_filter": {
"numeric_range": {
"years": {
"from": 12.4,
Oops, something went wrong.

0 comments on commit 59ed55f

Please sign in to comment.