1

Dynamic value or a variable doesn't work inside a elasticsearch "range" query.

For explaining more this is a elasticsearch range query which find productId from 1000 to 11100, which is working perfectly ---

$json = '{
   "query" : {
       "range" : {
           "productId" : {
               "from" : '1000',
               "to" : '11100'
           }
       }
   }
}';

On the other hand using the same query with a variable with the same value it returns me error like ---

{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures

$a =1000;
$b = 11100;

$json = '{
       "query" : {
           "range" : {
               "productId" : {
                   "from" : '$a',
                   "to" : '$b'
               }
           }
       }
    }';

Do anyone knows where i am making the mistake.

Any suggestion will be great help. Thanks in advanced.

3
  • what happened when you remove the quote around $a and $b (exemple : "from" : $a instead of "from" : '$a') Commented Aug 11, 2015 at 15:54
  • @vincent it also returns the same error, i have tried it in many ways -- $a and '.$a.' Commented Aug 11, 2015 at 19:01
  • could you paste the full error? Commented Aug 12, 2015 at 8:25

1 Answer 1

1

If this is PHP, there's a problem with string concatenation:

$a = 1000;
$b = 11100;

$json = '{
   "query" : {
       "range" : {
           "productId" : {
               "from" : '.$a.',
               "to" : '.$b.'
           }
       }
   }
}';

see the dots around the variables.

If you run the original piece of code by itself, the PHP parser should give you a parse error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.