[with PERL] Search in two index syntax


(Jérome) #1

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 !


(Clinton Gormley) #2

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


(Jérome) #3

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 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


(Jérome) #4

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']/
_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 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 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


(Clinton Gormley) #5

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']/
_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 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 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


(system) #6