Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-2603 Use the painless scripting language with Elasticsearch 5+
Because groovy has been deprecated, because painless doesn't require any server-side configuration, and because only painless is supported on Amazon Web Services.
- Loading branch information
Showing
11 changed files
with
137 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...c/main/java/org/hibernate/search/elasticsearch/query/impl/Elasticsearch2QueryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.query.impl; | ||
|
||
import org.hibernate.search.elasticsearch.impl.JsonBuilder; | ||
import org.hibernate.search.spatial.Coordinates; | ||
|
||
import com.google.gson.JsonObject; | ||
|
||
/** | ||
* @author Yoann Rodiere | ||
*/ | ||
public class Elasticsearch2QueryFactory implements ElasticsearchQueryFactory { | ||
|
||
@Override | ||
public JsonObject createSpatialDistanceScript(Coordinates center, String spatialFieldName) { | ||
return JsonBuilder.object() | ||
.add( "params", | ||
JsonBuilder.object() | ||
.addProperty( "lat", center.getLatitude() ) | ||
.addProperty( "lon", center.getLongitude() ) | ||
) | ||
// We multiply by 0.001 to Convert from meters to kilometers | ||
.addProperty( | ||
"inline", | ||
"doc['" + spatialFieldName + "'] ?" | ||
+ " doc['" + spatialFieldName + "'].arcDistance(lat,lon)*0.001" | ||
+ " : null" ) | ||
.addProperty( "lang", "groovy" ) | ||
.build(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...c/main/java/org/hibernate/search/elasticsearch/query/impl/Elasticsearch5QueryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.query.impl; | ||
|
||
import org.hibernate.search.elasticsearch.impl.JsonBuilder; | ||
import org.hibernate.search.spatial.Coordinates; | ||
|
||
import com.google.gson.JsonObject; | ||
|
||
/** | ||
* @author Yoann Rodiere | ||
*/ | ||
public class Elasticsearch5QueryFactory implements ElasticsearchQueryFactory { | ||
|
||
@Override | ||
public JsonObject createSpatialDistanceScript(Coordinates center, String spatialFieldName) { | ||
return JsonBuilder.object() | ||
.add( "params", | ||
JsonBuilder.object() | ||
.addProperty( "lat", center.getLatitude() ) | ||
.addProperty( "lon", center.getLongitude() ) | ||
) | ||
// We multiply by 0.001 to Convert from meters to kilometers | ||
.addProperty( | ||
"inline", | ||
"doc['" + spatialFieldName + "'].value !== null ?" | ||
+ " doc['" + spatialFieldName + "'].arcDistance(params.lat,params.lon)*0.001" | ||
+ " : null" ) | ||
.addProperty( "lang", "painless" ) | ||
.build(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...rc/main/java/org/hibernate/search/elasticsearch/query/impl/ElasticsearchQueryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.query.impl; | ||
|
||
import org.hibernate.search.spatial.Coordinates; | ||
|
||
import com.google.gson.JsonObject; | ||
|
||
/** | ||
* An object responsible for creating parts of an Elasticsearch JSON query. | ||
* <p> | ||
* Should eventually be responsible for building the whole JSON query, | ||
* see HSEARCH-2750. | ||
* | ||
* @see <a href="https://hibernate.atlassian.net/browse/HSEARCH-2750">HSEARCH-2750</a> | ||
* | ||
* @author Yoann Rodiere | ||
*/ | ||
public interface ElasticsearchQueryFactory { | ||
|
||
JsonObject createSpatialDistanceScript(Coordinates center, String spatialFieldName); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters