# Trouble with \_msearch, Unexpected character (':' (code 58)):

**URL:** <https://discuss.elastic.co/t/trouble-with--msearch-unexpected-character-code-58/10139>\
**Category:** Elasticsearch\
**Created:** [December 20, 2012, 8:59pm UTC](https://discuss.elastic.co/t/trouble-with--msearch-unexpected-character-code-58/10139 "2012-12-20T20:59:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Boon](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@David\_Boon](https://discuss.elastic.co/u/David_Boon)\
**Post date:** [December 20, 2012, 8:59pm UTC](https://discuss.elastic.co/t/trouble-with--msearch-unexpected-character-code-58/10139/1 "2012-12-20T20:59:14Z")

</div>

I'm having some trouble getting a search to work. I started with a working  
query against one index, here's the query that works with one index:

curl -s -v -XGET [http://localhost:9200/persons/\_search?pretty=true](http://localhost:9200/persons/_search?pretty=true) -d '  
{"query": {"filtered": {  
"query": {  
"query\_string": {  
"fields":["\_id", "firstName", "lastName"],  
"query":"\*"  
}  
}}}}  
'

That query returns records, everything ok. Now I've changed the query to  
use \_msearch, here's the new query:

curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '  
{"index": "persons"}  
{"query": {"filtered": {  
"query": {  
"query\_string": {  
"fields":["\_id", "firstName", "lastName"],  
"query":"_"  
}  
}}}}  
{"index": "groups"}  
{"query": {"filtered": {  
"query": {  
"query\_string": {  
"fields":["\_id", "name", "description"],  
"query":"_"  
}  
}}}}  
'

That query generates the following error:

"error" : "Unexpected character (':' (code 58)): expected a valid value  
(number, String, array, object, 'true', 'false' or 'null')\n at [Source:  
[B@1e44e3e9; line: 1, column: 299]"

My elastic search version is 0.19.10.

Thanks for any help on determining why I'm getting this error.

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 20, 2012, 10:10pm UTC](https://discuss.elastic.co/t/trouble-with--msearch-unexpected-character-code-58/10139/2 "2012-12-20T22:10:05Z")

</div>

The queries in multi search shouldn't contain new lines ('\n'). Try this:

curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '{"index":  
"persons"}  
{"query": {"filtered": { "query": { "query\_string": {"fields":["\_id",  
"firstName", "lastName"], "query":"_"}}}}}  
{"index": "groups"}  
{"query": {"filtered": {"query": {"query\_string": {"fields":["\_id", "name",  
"description"], "query":"_"}}}}}  
'

On Thursday, December 20, 2012 3:59:14 PM UTC-5, David Boon wrote:

> I'm having some trouble getting a search to work. I started with a  
> working query against one index, here's the query that works with one index:
> 
> curl -s -v -XGET [http://localhost:9200/persons/\_search\?pretty\=true](http://localhost:9200/persons/_search%5C?pretty%5C=true) -d '  
> {"query": {"filtered": {  
> "query": {  
> "query\_string": {  
> "fields":["\_id", "firstName", "lastName"],  
> "query":"\*"  
> }  
> }}}}  
> '
> 
> That query returns records, everything ok. Now I've changed the query to  
> use \_msearch, here's the new query:
> 
> curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '  
> {"index": "persons"}  
> {"query": {"filtered": {  
> "query": {  
> "query\_string": {  
> "fields":["\_id", "firstName", "lastName"],  
> "query":"_"  
> }  
> }}}}  
> {"index": "groups"}  
> {"query": {"filtered": {  
> "query": {  
> "query\_string": {  
> "fields":["\_id", "name", "description"],  
> "query":"_"  
> }  
> }}}}  
> '
> 
> That query generates the following error:
> 
> "error" : "Unexpected character (':' (code 58)): expected a valid value  
> (number, String, array, object, 'true', 'false' or 'null')\n at [Source:  
> [B@1e44e3e9; line: 1, column: 299]"
> 
> My Elasticsearch version is 0.19.10.
> 
> Thanks for any help on determining why I'm getting this error.

--

---

<div class="post-metadata">

**Author:** ![David\_Boon](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@David\_Boon](https://discuss.elastic.co/u/David_Boon)\
**Post date:** [December 21, 2012, 3:18pm UTC](https://discuss.elastic.co/t/trouble-with--msearch-unexpected-character-code-58/10139/3 "2012-12-21T15:18:06Z")

</div>

Thanks, I suppose that should have been more obvious to me since I grasped  
the spacing around "index".

This works:  
curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '  
{"index": "persons"}  
{"query": {"filtered": {"query": { "query\_string": { "fields":["\_id",  
"firstName", "lastName"], "query":"_" } }}}}  
{"index": "groups"}  
{"query": {"filtered": { "query": { "query\_string": { "fields":["\_id",  
"name", "description"], "query":"_" } }}}}  
'

It seems like a weakness to rely on spacing to delineate anything at all,  
especially in a structured document like json. Maybe it's not a big deal  
if you're using a driver, maybe only a problem for the rest api.

Thanks again!

On Thursday, December 20, 2012 5:10:05 PM UTC-5, Igor Motov wrote:

> The queries in multi search shouldn't contain new lines ('\n'). Try this:
> 
> curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '{"index":  
> "persons"}  
> {"query": {"filtered": { "query": { "query\_string": {"fields":["\_id",  
> "firstName", "lastName"], "query":"_"}}}}}  
> {"index": "groups"}  
> {"query": {"filtered": {"query": {"query\_string": {"fields":["\_id",  
> "name", "description"], "query":"_"}}}}}  
> '
> 
> On Thursday, December 20, 2012 3:59:14 PM UTC-5, David Boon wrote:
> 
> > I'm having some trouble getting a search to work. I started with a  
> > working query against one index, here's the query that works with one index:
> > 
> > curl -s -v -XGET [http://localhost:9200/persons/\_search\?pretty\=true](http://localhost:9200/persons/_search%5C?pretty%5C=true) -d '  
> > {"query": {"filtered": {  
> > "query": {  
> > "query\_string": {  
> > "fields":["\_id", "firstName", "lastName"],  
> > "query":"\*"  
> > }  
> > }}}}  
> > '
> > 
> > That query returns records, everything ok. Now I've changed the query to  
> > use \_msearch, here's the new query:
> > 
> > curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '  
> > {"index": "persons"}  
> > {"query": {"filtered": {  
> > "query": {  
> > "query\_string": {  
> > "fields":["\_id", "firstName", "lastName"],  
> > "query":"_"  
> > }  
> > }}}}  
> > {"index": "groups"}  
> > {"query": {"filtered": {  
> > "query": {  
> > "query\_string": {  
> > "fields":["\_id", "name", "description"],  
> > "query":"_"  
> > }  
> > }}}}  
> > '
> > 
> > That query generates the following error:
> > 
> > "error" : "Unexpected character (':' (code 58)): expected a valid  
> > value (number, String, array, object, 'true', 'false' or 'null')\n at  
> > [Source: [B@1e44e3e9; line: 1, column: 299]"
> > 
> > My Elasticsearch version is 0.19.10.
> > 
> > Thanks for any help on determining why I'm getting this error.

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 22, 2012, 12:35am UTC](https://discuss.elastic.co/t/trouble-with--msearch-unexpected-character-code-58/10139/4 "2012-12-22T00:35:04Z")

</div>

Yes, it's an optimization hack in a sense and it's used only in two places

- bulk indexing and multi\_search. When node receives the multi\_search  
request, it parses the request on two levels: multi\_search level and search  
level. On the multi\_search level, elasticsearch is interested only in  
headers ({"index":....} parts), and on the search level - only in search  
requests. If everything was wrapped into a single json, the search requests  
would have to be parsed twice.

On Friday, December 21, 2012 10:18:06 AM UTC-5, David Boon wrote:

> Thanks, I suppose that should have been more obvious to me since I grasped  
> the spacing around "index".
> 
> This works:  
> curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '  
> {"index": "persons"}  
> {"query": {"filtered": {"query": { "query\_string": { "fields":["\_id",  
> "firstName", "lastName"], "query":"_" } }}}}  
> {"index": "groups"}  
> {"query": {"filtered": { "query": { "query\_string": { "fields":["\_id",  
> "name", "description"], "query":"_" } }}}}  
> '
> 
> It seems like a weakness to rely on spacing to delineate anything at all,  
> especially in a structured document like json. Maybe it's not a big deal  
> if you're using a driver, maybe only a problem for the rest api.
> 
> Thanks again!
> 
> On Thursday, December 20, 2012 5:10:05 PM UTC-5, Igor Motov wrote:
> 
> > The queries in multi search shouldn't contain new lines ('\n'). Try this:
> > 
> > curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d  
> > '{"index": "persons"}  
> > {"query": {"filtered": { "query": { "query\_string": {"fields":["\_id",  
> > "firstName", "lastName"], "query":"_"}}}}}  
> > {"index": "groups"}  
> > {"query": {"filtered": {"query": {"query\_string": {"fields":["\_id",  
> > "name", "description"], "query":"_"}}}}}  
> > '
> > 
> > On Thursday, December 20, 2012 3:59:14 PM UTC-5, David Boon wrote:
> > 
> > > I'm having some trouble getting a search to work. I started with a  
> > > working query against one index, here's the query that works with one index:
> > > 
> > > curl -s -v -XGET [http://localhost:9200/persons/\_search\?pretty\=true](http://localhost:9200/persons/_search%5C?pretty%5C=true) -d  
> > > '  
> > > {"query": {"filtered": {  
> > > "query": {  
> > > "query\_string": {  
> > > "fields":["\_id", "firstName", "lastName"],  
> > > "query":"\*"  
> > > }  
> > > }}}}  
> > > '
> > > 
> > > That query returns records, everything ok. Now I've changed the query  
> > > to use \_msearch, here's the new query:
> > > 
> > > curl -s -v -XGET [http://localhost:9200/\_msearch?pretty=true](http://localhost:9200/_msearch?pretty=true) -d '  
> > > {"index": "persons"}  
> > > {"query": {"filtered": {  
> > > "query": {  
> > > "query\_string": {  
> > > "fields":["\_id", "firstName", "lastName"],  
> > > "query":"_"  
> > > }  
> > > }}}}  
> > > {"index": "groups"}  
> > > {"query": {"filtered": {  
> > > "query": {  
> > > "query\_string": {  
> > > "fields":["\_id", "name", "description"],  
> > > "query":"_"  
> > > }  
> > > }}}}  
> > > '
> > > 
> > > That query generates the following error:
> > > 
> > > "error" : "Unexpected character (':' (code 58)): expected a valid  
> > > value (number, String, array, object, 'true', 'false' or 'null')\n at  
> > > [Source: [B@1e44e3e9; line: 1, column: 299]"
> > > 
> > > My Elasticsearch version is 0.19.10.
> > > 
> > > Thanks for any help on determining why I'm getting this error.

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:58am UTC](https://discuss.elastic.co/t/trouble-with--msearch-unexpected-character-code-58/10139/5 "2017-07-06T02:58:42Z")

</div>


