You are looking at documentation for an older release.
Not what you want? See the
current release documentation.
Specialized queriesedit
This group contains queries which do not fit into the other groups:
-
more_like_thisquery - This query finds documents which are similar to the specified text, document, or collection of documents.
-
scriptquery -
This query allows a script to act as a filter. Also see the
function_scorequery. -
percolatequery - This query finds percolator queries based on documents.
More Like This Query (mlt)edit
See: * More Like This Query
Script Queryedit
See Script Query
If you have stored on each data node a script named myscript.painless with:
doc['num1'].value > params.param1
You can use it then with:
Percolate Queryedit
See: * Percolate Query
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9300)));Before the percolate query can be used an percolator mapping should be added and
a document containing a percolator query should be indexed:
// create an index with a percolator field with the name 'query':
client.admin().indices().prepareCreate("myIndexName")
.addMapping("query", "query", "type=percolator")
.addMapping("docs", "content", "type=text")
.get();
//This is the query we're registering in the percolator
QueryBuilder qb = termQuery("content", "amazing");
//Index the query = register it in the percolator
client.prepareIndex("myIndexName", "query", "myDesignatedQueryName")
.setSource(jsonBuilder()
.startObject()
.field("query", qb) // Register the query
.endObject())
.setRefreshPolicy(RefreshPolicy.IMMEDIATE) // Needed when the query shall be available immediately
.get();This indexes the above term query under the name myDesignatedQueryName.
In order to check a document against the registered queries, use this code:
//Build a document to check against the percolator
XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();
docBuilder.field("content", "This is amazing!");
docBuilder.endObject(); //End of the JSON root object
PercolateQueryBuilder percolateQuery = new PercolateQueryBuilder("query", "docs", docBuilder.bytes());
// Percolate, by executing the percolator query in the query dsl:
SearchResponse response = client().prepareSearch("myIndexName")
.setQuery(percolateQuery))
.get();
//Iterate over the results
for(SearchHit hit : response.getHits()) {
// Percolator queries as hit
}