# \[with PERL\] Search in two index syntax

**URL:** <https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539>\
**Category:** Elasticsearch\
**Created:** [May 2, 2012, 1:12pm UTC](https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539 "2012-05-02T13:12:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [May 2, 2012, 1:12pm UTC](https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539/1 "2012-05-02T13:12:38Z")

</div>

Hi everybody !

I have just one little question :

I want search in two index using PERL.

The doc says for 2 types but i want search in 2 index and some types  
too.

* * *

FROM DOC :

* * *

$result = $es-\>searchqs(  
index =\> undef, # all  
type =\> ['user','tweet'],  
q =\> 'john smith'  
);

* * *

## So m'y question is :

What is the good syntax in my code :

I've try that but doesn't works :

$result = $es-\>searchqs(  
index =\> ['foo', 'bar', 'toto'],  
type =\> ['user', 'tweet', 'toto'],  
q =\> 'test'  
};

Thanks !

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 2, 2012, 3:20pm UTC](https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539/2 "2012-05-02T15:20:47Z")

</div>

Hi Jerome

> I want search in two index using PERL.

> I've try that but doesn't works :
> 
> $result = $es-\>searchqs(  
> index =\> ['foo', 'bar', 'toto'],  
> type =\> ['user', 'tweet', 'toto'],  
> q =\> 'test'  
> };

That is the correct syntax. Why do you think it is incorrect?

clint

---

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [May 3, 2012, 8:56am UTC](https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539/3 "2012-05-03T08:56:38Z")

</div>

Hi,  
Sorry, i've found the error, in my code i forgot a quote.

Thanks.

On 2 mai, 17:20, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hi Jerome
> 
> > I want search in two index using PERL.
> 
> > I've try that but doesn't works :
> 
> > $result = $es-\>searchqs(  
> > index =\> ['foo', 'bar', 'toto'],  
> > type =\> ['user', 'tweet', 'toto'],  
> > q =\> 'test'  
> > };
> 
> That is the correct syntax. Why do you think it is incorrect?
> 
> clint

---

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [May 3, 2012, 12:19pm UTC](https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539/4 "2012-05-03T12:19:53Z")

</div>

Finally i have a little problem :

* * *

ERROR

* * *

# [Thu May 3 14:15:14 2012] Protocol: http, Server:

193.51.160.124:9200  
curl -XGET '[http://127.0.0.1:9200/['plop']/['as'%2C'toto']/](http://127.0.0.1:9200/%5B'plop'%5D/%5B'as'%2C'toto'%5D/)  
\_search?pretty=1&q=melanogaster'

# [Thu May 3 14:15:14 2012] Response:

# {

# "status" : 404,

# "error" : "IndexMissingException[[['plop']] missing]"

# }

[ERROR] \*\* Elasticsearch::Error::Missing at /Library/Perl/5.10.0/  
Elasticsearch/Transport/HTTP.pm line 60 :  
IndexMissingException[[['plop']] missing]

With vars:{  
'request' =\> {  
'post\_process' =\> undef,  
'qs' =\> {  
'q' =\> 'melanogaster'  
},  
'cmd' =\> '/%5B'plop'%5D/%5B'as'%2C'toto'%5D/\_search',  
'as\_json' =\> undef,  
'data' =\> undef,  
'method' =\> 'GET'  
},  
'status\_code' =\> 404,  
'server' =\> '193.51.160.124:9200',  
'status\_msg' =\> 'Not Found'  
}

* * *

My code

* * *

if($choice eq 'y'){  
restreindre\_recherche($es, @zone\_index, @zone\_type);

```
						#Format index
						$index = join('\',\'', @zone_index);
						$index = '[\''.$index.'\']';

						$affine = 1;
					}

					if($affine == 0){ #Search in _all
						$result = $es->searchqs(
							index	=>	undef,
							q => $keyword
						);
					}
					elsif($affine == 0 || !defined(@zone_type)){ #Search in multi

```

index and all type  
$result = $es-\>searchqs(  
index =\> $index,  
q =\> $keyword  
);  
}  
else{ #Elastic Search in multi index and multi type  
#Format type  
$types = join('','', @zone\_type);  
$types = '[''.$types.'']';

```
						$result = $es->searchqs(
							index	=>	$index,
							type	=>	$types,
							q =>	$keyword
						);
					}

```

On 3 mai, 10:56, Jérome [pivertjer...@gmail.com](mailto:pivertjer...@gmail.com) wrote:

> Hi,  
> Sorry, i've found the error, in my code i forgot a quote.
> 
> Thanks.
> 
> On 2 mai, 17:20, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:
> 
> > Hi Jerome
> 
> > > I want search in two index using PERL.
> 
> > > I've try that but doesn't works :
> 
> > > $result = $es-\>searchqs(  
> > > index =\> ['foo', 'bar', 'toto'],  
> > > type =\> ['user', 'tweet', 'toto'],  
> > > q =\> 'test'  
> > > };
> 
> > That is the correct syntax. Why do you think it is incorrect?
> 
> > clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 3, 2012, 12:21pm UTC](https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539/5 "2012-05-03T12:21:54Z")

</div>

On Thu, 2012-05-03 at 05:19 -0700, JÃ©rome wrote:

> Finally i have a little problem :

You are doing { index =\> "['plop','toto']" }

You should be doing { index =\> ['plop','toto']}

clint

That'

> * * *
> 
> ERROR
> 
> * * *
> 
> # [Thu May 3 14:15:14 2012] Protocol: http, Server:
> 
> 193.51.160.124:9200  
> curl -XGET '[http://127.0.0.1:9200/['plop']/['as'%2C'toto']/](http://127.0.0.1:9200/%5B'plop'%5D/%5B'as'%2C'toto'%5D/)  
> \_search?pretty=1&q=melanogaster'
> 
> # [Thu May 3 14:15:14 2012] Response:
> 
> # {
> 
> # "status" : 404,
> 
> # "error" : "IndexMissingException[[['plop']] missing]"
> 
> # }
> 
> [ERROR] \*\* Elasticsearch::Error::Missing at /Library/Perl/5.10.0/  
> Elasticsearch/Transport/HTTP.pm line 60 :  
> IndexMissingException[[['plop']] missing]
> 
> With vars:{  
> 'request' =\> {  
> 'post\_process' =\> undef,  
> 'qs' =\> {  
> 'q' =\> 'melanogaster'  
> },  
> 'cmd' =\> '/%5B'plop'%5D/%5B'as'%2C'toto'%5D/\_search',  
> 'as\_json' =\> undef,  
> 'data' =\> undef,  
> 'method' =\> 'GET'  
> },  
> 'status\_code' =\> 404,  
> 'server' =\> '193.51.160.124:9200',  
> 'status\_msg' =\> 'Not Found'  
> }
> 
> * * *
> 
> My code
> 
> * * *
> 
> if($choice eq 'y'){  
> restreindre\_recherche($es, @zone\_index, @zone\_type);
> 
> ```
> #Format index
> $index = join('\',\'', @zone_index);
> $index = '[\''.$index.'\']';
> 
> $affine = 1;
> }
> 
> if($affine == 0){ #Search in _all
> $result = $es->searchqs(
> index	=>	undef,
> q => $keyword
> );
> }
> elsif($affine == 0 || !defined(@zone_type)){ #Search in multi
> 
> ```
> 
> index and all type  
> $result = $es-\>searchqs(  
> index =\> $index,  
> q =\> $keyword  
> );  
> }  
> else{ #search in multi index and multi type  
> #Format type  
> $types = join('','', @zone\_type);  
> $types = '[''.$types.'']';
> 
> ```
> $result = $es->searchqs(
> index	=>	$index,
> type	=>	$types,
> q =>	$keyword
> );
> }
> 
> ```
> 
> On 3 mai, 10:56, JÃ©rome [pivertjer...@gmail.com](mailto:pivertjer...@gmail.com) wrote:
> 
> > Hi,  
> > Sorry, i've found the error, in my code i forgot a quote.
> > 
> > Thanks.
> > 
> > On 2 mai, 17:20, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:
> > 
> > > Hi Jerome
> > 
> > > > I want search in two index using PERL.
> > 
> > > > I've try that but doesn't works :
> > 
> > > > $result = $es-\>searchqs(  
> > > > index =\> ['foo', 'bar', 'toto'],  
> > > > type =\> ['user', 'tweet', 'toto'],  
> > > > q =\> 'test'  
> > > > };
> > 
> > > That is the correct syntax. Why do you think it is incorrect?
> > 
> > > clint

---

<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, 3:30am UTC](https://discuss.elastic.co/t/with-perl-search-in-two-index-syntax/7539/6 "2017-07-06T03:30:13Z")

</div>


