# Multiple search terms

**URL:** <https://discuss.elastic.co/t/multiple-search-terms/9055>\
**Category:** Elasticsearch\
**Created:** [September 18, 2012, 5:18pm UTC](https://discuss.elastic.co/t/multiple-search-terms/9055 "2012-09-18T17:18:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Devine](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@James\_Devine](https://discuss.elastic.co/u/James_Devine)\
**Post date:** [September 18, 2012, 5:18pm UTC](https://discuss.elastic.co/t/multiple-search-terms/9055/1 "2012-09-18T17:18:29Z")

</div>

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](mailto:jdevine555@rapidnet.com) ',  
'message\_size' =\> 1997,  
'subject' =\> 'hello there  
',  
'date' =\> '1343069700',  
'from' =\> 'James Devine \<  
[gwisvalyou555@valyou.net](mailto:gwisvalyou555@valyou.net)\> '  
},  
'\_index' =\> 'messages',  
'\_id' =\>  
'1076fd19e3a4fb6e1adf699bf1dc8b35.f75c6c5c725f701a527e9d25cab5d7d3dac13e04.1343069700',  
'\_type' =\> 'search'  
},  
{  
'sort' =\> [  
1328745866  
],  
'\_score' =\> undef,  
'fields' =\> {  
'to' =\> '\<  
[jdevine555@rapidnet.com](mailto:jdevine555@rapidnet.com)\> ',  
'message\_size' =\> 39296,  
'subject' =\> 'Re: hello ',  
'date' =\> '1328745866',  
'from' =\> 'James Devine \<  
[fxmulder@gmail.com](mailto:fxmulder@gmail.com)\> '  
},  
'\_index' =\> 'messages',  
'\_id' =\>  
'879cf81c213a964e3f617cb594171bda.a38165c15af7088f686b8b7616a9728e68c25a9a.1328745866',  
'\_type' =\> 'search'  
},  
{  
'sort' =\> [  
1328032551  
],  
'\_score' =\> undef,  
'fields' =\> {  
'to' =\> '  
[jdevine555@rapidnet.com](mailto:jdevine555@rapidnet.com) ',  
'message\_size' =\> 578,  
'subject' =\> 'hello ',  
'date' =\> '1328032551',  
'from' =\> 'Gwisenet \<  
[gwisenet555@enetis.net](mailto: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?

--

---

<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:12am UTC](https://discuss.elastic.co/t/multiple-search-terms/9055/2 "2017-07-06T03:12:26Z")

</div>

Closed on July 6, 2017, 3:12am UTC


