migrate_query_refactoring.asciidoc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. [[breaking-changes query-refactoring]]
  2. == Breaking changes on the query-refactoring branch
  3. This section discusses changes that are breaking to the current rest or java-api
  4. on the query-refactoring feature branch.
  5. === Plugins
  6. Plugins implementing custom queries need to implement the `fromXContent(QueryParseContext)` method in their
  7. `QueryParser` subclass rather than `parse`. This method will take care of parsing the query from `XContent` format
  8. into an intermediate query representation that can be streamed between the nodes in binary format, effectively the
  9. query object used in the java api. Also, the query parser needs to implement the `getBuilderPrototype` method that
  10. returns a prototype of the `NamedWriteable` query, which allows to deserialize an incoming query by calling
  11. `readFrom(StreamInput)` against it, which will create a new object, see usages of `Writeable`. The `QueryParser`
  12. also needs to declare the generic type of the query that it supports and it's able to parse.
  13. The query object can then transform itself into a lucene query through the new `toQuery(QueryShardContext)` method,
  14. which returns a lucene query to be executed on the data node.
  15. Similarly, plugins implementing custom score functions need to implement the `fromXContent(QueryParseContext)`
  16. method in their `ScoreFunctionParser` subclass rather than `parse`. This method will take care of parsing
  17. the function from `XContent` format into an intermediate function representation that can be streamed between
  18. the nodes in binary format, effectively the function object used in the java api. Also, the query parser needs
  19. to implement the `getBuilderPrototype` method that returns a prototype of the `NamedWriteable` function, which
  20. allows to deserialize an incoming function by calling `readFrom(StreamInput)` against it, which will create a
  21. new object, see usages of `Writeable`. The `ScoreFunctionParser` also needs to declare the generic type of the
  22. function that it supports and it's able to parse. The function object can then transform itself into a lucene
  23. function through the new `toFunction(QueryShardContext)` method, which returns a lucene function to be executed
  24. on the data node.
  25. === Java-API
  26. ==== BoostingQueryBuilder
  27. Removed setters for mandatory positive/negative query. Both arguments now have
  28. to be supplied at construction time already and have to be non-null.
  29. ==== SpanContainingQueryBuilder
  30. Removed setters for mandatory big/little inner span queries. Both arguments now have
  31. to be supplied at construction time already and have to be non-null. Updated
  32. static factory methods in QueryBuilders accordingly.
  33. ==== SpanOrQueryBuilder
  34. Making sure that query contains at least one clause by making initial clause mandatory
  35. in constructor.
  36. ==== SpanNearQueryBuilder
  37. Removed setter for mandatory slop parameter, needs to be set in constructor now. Also
  38. making sure that query contains at least one clause by making initial clause mandatory
  39. in constructor. Updated the static factory methods in QueryBuilders accordingly.
  40. ==== SpanNotQueryBuilder
  41. Removed setter for mandatory include/exclude span query clause, needs to be set in constructor now.
  42. Updated the static factory methods in QueryBuilders and tests accordingly.
  43. ==== SpanWithinQueryBuilder
  44. Removed setters for mandatory big/little inner span queries. Both arguments now have
  45. to be supplied at construction time already and have to be non-null. Updated
  46. static factory methods in QueryBuilders accordingly.
  47. ==== QueryFilterBuilder
  48. Removed the setter `queryName(String queryName)` since this field is not supported
  49. in this type of query. Use `FQueryFilterBuilder.queryName(String queryName)` instead
  50. when in need to wrap a named query as a filter.
  51. ==== WrapperQueryBuilder
  52. Removed `wrapperQueryBuilder(byte[] source, int offset, int length)`. Instead simply
  53. use `wrapperQueryBuilder(byte[] source)`. Updated the static factory methods in
  54. QueryBuilders accordingly.
  55. ==== QueryStringQueryBuilder
  56. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  57. Use the `field(String, float)` method instead.
  58. ==== Operator
  59. Removed the enums called `Operator` from `MatchQueryBuilder`, `QueryStringQueryBuilder`,
  60. `SimpleQueryStringBuilder`, and `CommonTermsQueryBuilder` in favour of using the enum
  61. defined in `org.elasticsearch.index.query.Operator` in an effort to consolidate the
  62. codebase and avoid duplication.
  63. ==== queryName and boost support
  64. Support for `queryName` and `boost` has been streamlined to all of the queries. That is
  65. a breaking change till queries get sent over the network as serialized json rather
  66. than in `Streamable` format. In fact whenever additional fields are added to the json
  67. representation of the query, older nodes might throw error when they find unknown fields.
  68. ==== InnerHitsBuilder
  69. InnerHitsBuilder now has a dedicated addParentChildInnerHits and addNestedInnerHits methods
  70. to differentiate between inner hits for nested vs. parent / child documents. This change
  71. makes the type / path parameter mandatory.
  72. ==== MatchQueryBuilder
  73. Moving MatchQueryBuilder.Type and MatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.Type.
  74. Also reusing new Operator enum.
  75. ==== MoreLikeThisQueryBuilder
  76. Removed `MoreLikeThisQueryBuilder.Item#id(String id)`, `Item#doc(BytesReference doc)`,
  77. `Item#doc(XContentBuilder doc)`. Use provided constructors instead.
  78. Removed `MoreLikeThisQueryBuilder#addLike` in favor of texts and/or items beeing provided
  79. at construction time. Using arrays there instead of lists now.
  80. Removed `MoreLikeThisQueryBuilder#addUnlike` in favor to using the `unlike` methods
  81. which take arrays as arguments now rather than the lists used before.
  82. The deprecated `docs(Item... docs)`, `ignoreLike(Item... docs)`,
  83. `ignoreLike(String... likeText)`, `addItem(Item... likeItems)` have been removed.
  84. ==== GeoDistanceQueryBuilder
  85. Removing individual setters for lon() and lat() values, both values should be set together
  86. using point(lon, lat).
  87. ==== GeoDistanceRangeQueryBuilder
  88. Removing setters for to(Object ...) and from(Object ...) in favour of the only two allowed input
  89. arguments (String, Number). Removing setter for center point (point(), geohash()) because parameter
  90. is mandatory and should already be set in constructor.
  91. Also removing setters for lt(), lte(), gt(), gte() since they can all be replaced by equivallent
  92. calls to to/from() and inludeLower()/includeUpper().
  93. ==== GeoPolygonQueryBuilder
  94. Require shell of polygon already to be specified in constructor instead of adding it pointwise.
  95. This enables validation, but makes it necessary to remove the addPoint() methods.
  96. ==== MultiMatchQueryBuilder
  97. Moving MultiMatchQueryBuilder.ZeroTermsQuery enum to MatchQuery.ZeroTermsQuery.
  98. Also reusing new Operator enum.
  99. Removed ability to pass in boost value using `field(String field)` method in form e.g. `field^2`.
  100. Use the `field(String, float)` method instead.
  101. ==== MissingQueryBuilder
  102. The two individual setters for existence() and nullValue() were removed in favour of
  103. optional constructor settings in order to better capture and validate their interdependent
  104. settings at construction time.
  105. ==== TermsQueryBuilder
  106. Remove the setter for `termsLookup()`, making it only possible to either use a TermsLookup object or
  107. individual values at construction time. Also moving individual settings for the TermsLookup (lookupIndex,
  108. lookupType, lookupId, lookupPath) to the separate TermsLookup class, using constructor only and moving
  109. checks for validation there. Removed `TermsLookupQueryBuilder` in favour of `TermsQueryBuilder`.
  110. ==== FunctionScoreQueryBuilder
  111. `add` methods have been removed, all filters and functions must be provided as constructor arguments by
  112. creating an array of `FunctionScoreQueryBuilder.FilterFunctionBuilder` objects, containing one element
  113. for each filter/function pair.
  114. `scoreMode` and `boostMode` can only be provided using corresponding enum members instead
  115. of string values: see `FilterFunctionScoreQuery.ScoreMode` and `CombineFunction`.
  116. `CombineFunction.MULT` has been renamed to `MULTIPLY`.