PercolateException[failed to percolate]; nested - Percolate API on nested document - elasticsearch

I am using elasticsearch 1.1.
Normally in this version, percolator on nested documents should work.
Although, i am trying to do this but I get the following error:
failures: [
{
index: test
shard: 4
reason: BroadcastShardOperationFailedException[[test][4] ]; nested: PercolateException[failed to percolate]; nested: ElasticsearchIllegalArgumentException[Nothing to percolate];
}
]
I have the following percolator (sorry elasticsearch head removed me all the quotes):
{
_index: test
_type: .percolator
_id: 27
_version: 1
_score: 1
_source: {
query: {
filtered: {
query: {
match_all: { }
}
filter: {
nested: {
filter: {
term: {
city: london
}
}
path: location
}
}
}
}
}
}
And while trying to percolate this document I am getting the error:
{
...
"location": {
"date": "2014-05-05T15:07:58",
"namedplaces": {
"city": "london"
}
}
}
Any idea why it doesn't work ?
EDIT :
In elasticsearch log I got more precision about the error:
[2014-05-06 13:33:48,972][DEBUG][action.percolate ] [Tomazooma] [test][2], node[H42BBxajRs2w2NmllMnp7g], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.percolate.PercolateReque
st#7399452e]
org.elasticsearch.percolator.PercolateException: failed to percolate
at org.elasticsearch.action.percolate.TransportPercolateAction.shardOperation(TransportPercolateAction.java:198)
at org.elasticsearch.action.percolate.TransportPercolateAction.shardOperation(TransportPercolateAction.java:55)
at org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction$AsyncBroadcastAction$2.run(TransportBroadcastOperationAction.java:226)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.elasticsearch.ElasticsearchIllegalArgumentException: Nothing to percolate
at org.elasticsearch.percolator.PercolatorService.percolate(PercolatorService.java:187)
at org.elasticsearch.action.percolate.TransportPercolateAction.shardOperation(TransportPercolateAction.java:194)
... 5 more

The documentation of ES is not really clear about it. But when you look at this page, you will see that when you are percolating you need to surround your indexed document by doc{}. It is indeed compulsory otherwise the exception that you've got will appears:
Try to do so on :
{
"doc":{
...
"location": {
"date": "2014-05-05T15:07:58",
"namedplaces": {
"city": "london"
}
}
}
}
I hope it will help ;-)

Another reason for the Nothing to percolate exception is not setting the Content-Length HTTP header.
Because the GET request has a body, it should also have a 'Content-Length' HTTP header, but not all APIs will set this for you; as I found out the hard way!

Related

Is the order appear on `should` impact query result?

I am using elasticsearch 6.8 and below is a sample of query I send:
{
"query": {
...
"bool": {
"should": [
{ match_phrase: { descriptor: 'xxx' } },
{ match_phrase: { descriptor: 'xxx' } },
{ match_phrase: { descriptor: 'xxx' } },
{ match_phrase: { descriptor: 'xxx' } }
]
}
...
}
As you can see there are many match_phrase under should array. Is the order of these match matter in terms of scores in the result?
The filter parameter indicates filter context. Its term and range clauses are used in filter context. They will filter out documents which do not match, but they WILL NOT affect the score for matching documents.
Please also see the document of ElasticSearch as a reference.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html

Elasticsearch match with filter

I need a query that makes partial match on a string and filter outside documents that have a specific value for a field.
I tried this payload for es:
payload = {
search_request: {
_source: [ 'name', 'source','pg_id' ],
query: {
match: { name: query_string }
bool: {
must_not: {
term: { "source.source": source_value }
}
}
},
size: 100
},
query_hint: query,
algorithm: algorithm,
field_mapping: { title: ["_source.name", "_source.source"]}
}
But ES trows this error:
{
:error=> {
:root_cause=> [
{
:type=>"parse_exception",
:reason=>
"failed to parse search source. expected field name but got [
START_OBJECT
] "}],
:type=>" search_phase_execution_exception",
:reason=>"all shards failed",
:phase=>"query",
:grouped=>true,
:failed_shards=> [
{
:shard=>0,
:index=>"articles",
:node=>"3BUP3eN_TB2-zExigd_k2g",
:reason=> {
:type=>"parse_exception",
:reason=>
"failed to parse search source. expected field name but got [
START_OBJECT
] "
}
}
]
},
:status=>400
}
I am using Elasticsearch 2.4
First of all your json format is not valid. Check for a commas and quotes.
Also if you need just to filtrate documents - filters are much faster than queries. Check documentation

ElasticsearchIllegalArgumentException[suggester [completion] requires context to be setup]

I am using Elastic Search to implement an autosuggest field for an index called people:
The Mapping is as below for the field person_name_suggest -
person_name_suggest: {
type: "completion",
analyzer: "simple",
payloads: true,
preserve_separators: true,
preserve_position_increments: true,
max_input_length: 50,
context: {
office_scope: {
type: "category",
path: "office_scope",
default: [
"0"
]
}
}
},
The request that I need to Elastic Search is as follows:
{
"suggest":{
"suggestions":{
"text":"M","
completion":{
"field":"person_name_suggest",
"context":890,
"size":10
}
}
}
}
I get the following error -
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[OsbgjmewT569a-7ZoNCMtg][people_2016_10_29][0]: SearchParseException[[people_2016_10_29][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"suggest":{"suggestions":{"text":"M","completion":{"field":"person_name_suggest","context":890,"size":10}}}}]]]; nested: ElasticsearchIllegalArgumentException[suggester [completion] requires context to be setup]; }
From what I can see, I have the completion suggester set up right.
Could someone point me in the right direction?
The version of ElasticSearch being used is 1.6
There is a syntax error in query. You have to specify the name of context
Try this
{
"suggest":{
"suggestions":{
"text":"M","
completion":{
"field":"person_name_suggest",
"context":{"office_scope":890},
"size":10
}
}
}
}

elasticsearch get statistics on analyzed field

i am trying to get statistics on analyzed string field.
i am trying to get AVG length of string field (in this example its title, and title sometimes can be empty/none).
tried:
GET book/_search
{
"facets" : {
"stat1" : {
"statistical" : {
"script" : "_source.title?.length()"
}
}
}
}
and i get an error:
Query Failed [Failed to execute main query]]; nested: NullPointerException; }]",
"status": 500
}
how can i accomplish that?
Any reason why you are using facets and not aggregations? Unless you use an Elasticsearch version that only supports facets, I recommend switching to aggregations. Facets are deprecated in 1.x and removed completely in 2.x.
And an aggregation like this one should work just fine:
GET /book/_search
{
"aggs": {
"stat1": {
"stats": {
"script": "_source.title?.length() ?: 0"
}
}
}
}

Searching in specific indices with JSON object

I have a problem. In my application I'm using ElasticSearch. I'm posting JSON object to my ElasticSearch server. That JSON object contain DSL query. So, what I need to do, is to query specific index for some data.
This is the query:
{
"query":{
"indices":{
"indices":[
"index-1"
],
"query":{
"bool":{
"must":[
{
"match":{
"_all":"this is test"
}
}
],
"should":[
{
"match":{
"country":"PL"
}
}
],
"minimum_should_match":1
}
},
"no_match_query":"none"
}
},
"from":0,
"size":10,
"sort":{
"name":{
"order":"ASC"
}
}
}
Query works just fine, it returns data which I want to. However, in ElasticSearch logs I can see:
[2015-05-28 22:08:20,942][DEBUG][action.search.type] [index] [twitter][0], node[X_ASxSKmn-Bzmn-nHLQ8g], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest#7b98e9ad] lastShard [true]
org.elasticsearch.search.SearchParseException: [twitter][0]: query[MatchNoDocsQuery],from[0],size[10]: Parse Failure [Failed to parse source [HERE_COMES_MY_JSON]]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:681)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:537)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:509)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:264)
at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.search.SearchParseException: [twitter][0]: query[MatchNoDocsQuery],from[0],size[10]: Parse Failure [No mapping found for [name] in order to sort on]
It tries to fetch something from twitter index, which is some standard out-of-the-box index for testing. Why? I specified that I want to search in index-1, not all of them.
I found workaround, just to add:
"ignore_unmapped" : true
in sort, but it's not really a solution.
I don't know if it matters, but I set up a REST which I'm calling, and inside my Java app I'm passing JSON to ElasticSearch like that:
Client client = new TransportClient(settings);
SearchRequestBuilder builder = client .prepareSearch().setSource(json);
SearchResponse response = builder.execute().actionGet();
Anyone have any clue what is wrong? I would really appreciate any
I think you misunderstood the functionality of indices here: it can be used when a certain query needs to be executed against a list of indices and another query that needs to be executed on indices that do not match the list of indices.
So, all depends on the indices you run this against.
For example:
GET /abc,test1,test2,test3/_search
{
"query": {
"indices": {
"indices": ["abc"],
"query": {
"bool": {
"must": [
...
will be run against abc, test1, test2, test3 indices. Indices that match "indices": ["abc"] will have the query run against. The other indices that don't match (in my example - test1, test2, test3) will have the query from no_match_query run against them.
So, it is important against which indices you run your indices query. And ignoring unmapped fields is the way to go here.

Resources