Multiple search terms


(James Devine) #1

I have created the following index:

$result = $es->create_index(
index => 'messages',
settings => {
number_of_shards => 20,
number_of_replicas => 1,
analysis => {
analyzer => {
email => {
tokenizer => 'uax_url_email',
filter => ['standard', 'lowercase']
}
}
}
},
mappings => {
search => {
properties => {
header_size => { type => 'integer', index
=> 'no' },
message_size => { type => 'integer', index
=> 'no' },
compressed_size => { type => 'integer',
index => 'no' },
compressed => { type => 'boolean', index =>
'no' },
sender => { type => 'string', analyzer =>
'email' },
recipients => { type => 'string', analyzer
=> 'email', index_name => 'recipient' },
date => { type => 'date' },
subject => { type => 'string' },
from => { type => 'string', analyzer =>
'email' },
to => { type => 'string', index => 'no' },
cc => { type => 'string', index => 'no' },
}
},
header => {
properties => {
content => { type => 'binary' }
}
},
full => {
properties => {
content => { type => 'binary' }
}
}
}
);

and I can perform the following search just fine:

my $results = $es->search(
{
'sort' => [
{
'date' => 'desc'
}
],
'index' => 'messages',
'fields' => [
'subject',
'from',
'to',
'message_size',
'date'
],
'from' => '0',
'query' => {
'constant_score' => {
'filter' => {
'and' => [
{

'term' => {

    'subject' => 'hello'

  }
                                                                  },
                                                                  {

'term' => {

    'recipient' => 'jdevine555@rapidnet.com'

  }
                                                                  }
                                                                ]
                                                     }
                                       }
                 },
      'track_scores' => 0,
      'type' => 'search',
      'size' => '20'
    }

);

with the following results:

$VAR1 = {
'hits' => {
'hits' => [
{
'sort' => [
1343069700
],
'_score' => undef,
'fields' => {
'to' => '
jdevine555@rapidnet.com ',
'message_size' => 1997,
'subject' => 'hello there
',
'date' => '1343069700',
'from' => 'James Devine <
gwisvalyou555@valyou.net> '
},
'_index' => 'messages',
'_id' =>
'1076fd19e3a4fb6e1adf699bf1dc8b35.f75c6c5c725f701a527e9d25cab5d7d3dac13e04.1343069700',
'_type' => 'search'
},
{
'sort' => [
1328745866
],
'_score' => undef,
'fields' => {
'to' => '<
jdevine555@rapidnet.com> ',
'message_size' => 39296,
'subject' => 'Re: hello ',
'date' => '1328745866',
'from' => 'James Devine <
fxmulder@gmail.com> '
},
'_index' => 'messages',
'_id' =>
'879cf81c213a964e3f617cb594171bda.a38165c15af7088f686b8b7616a9728e68c25a9a.1328745866',
'_type' => 'search'
},
{
'sort' => [
1328032551
],
'_score' => undef,
'fields' => {
'to' => '
jdevine555@rapidnet.com ',
'message_size' => 578,
'subject' => 'hello ',
'date' => '1328032551',
'from' => 'Gwisenet <
gwisenet555@enetis.net> '
},
'_index' => 'messages',
'_id' =>
'453d30bf6489a0878d9594301e2768cd.d03214cf844cb8367af3b4a7ad9d02051fe0e055.1328032551',
'_type' => 'search'
}
],
'max_score' => undef,
'total' => 3
},
'timed_out' => bless( do{(my $o = 0)}, 'JSON::XS::Boolean' ),
'_shards' => {
'failed' => 0,
'successful' => 20,
'total' => 20
},
'took' => 179
};

but when I try to add a second subject search term it does not seem to
match anymore even though it should match one of the returned items above:

my $results = $es->search(
{
'sort' => [
{
'date' => 'desc'
}
],
'index' => 'messages',
'fields' => [
'subject',
'from',
'to',
'message_size',
'date'
],
'from' => '0',
'query' => {
'constant_score' => {
'filter' => {
'and' => [
{

'term' => {

    'subject' => 'hello'

  }
                                                                  },
                                                                  {

'term' => {

    'subject' => 'there'

  }
                                                                  },
                                                                  {

'term' => {

    'recipient' => 'jdevine555@rapidnet.com'

  }
                                                                  }
                                                                ]
                                                     }
                                       }
                 },
      'track_scores' => 0,
      'type' => 'search',
      'size' => '20'
    }

);

This used to work on another install of elasticsearch but doesn't seem to
anymore, any idea what I might be doing wrong?

--


(system) #2