# Phrase Match with Filters

**URL:** <https://discuss.elastic.co/t/phrase-match-with-filters/9961>\
**Category:** Elasticsearch\
**Created:** [December 5, 2012, 9:58pm UTC](https://discuss.elastic.co/t/phrase-match-with-filters/9961 "2012-12-05T21:58:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbrianjones](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbrianjones/32/1402_2.png) [@tbrianjones](https://discuss.elastic.co/u/tbrianjones)\
**Post date:** [December 5, 2012, 9:58pm UTC](https://discuss.elastic.co/t/phrase-match-with-filters/9961/1 "2012-12-05T21:58:10Z")

</div>

I have an index called 'companies' that contains two types, 'company' and  
'file'. I'm trying to perform exact match queries on the 'file' types of a  
specific company. I am querying with phrases like "iso 9001" and would  
like to get exact match results across all indexed content for a 'file'  
type. This includes multiple strings, objects and a file. If my mappings  
are correct, I think the \_all field should be fine to search against in  
this case.

Below is my best guess at the correct ElasticSearch api query, but, having  
tried, many different variations, continue to fail. Please help.

curl -XPOST '[http://domain.com:9200/companies/\_search?pretty=true](http://domain.com:9200/companies/_search?pretty=true)' -d '  
{  
"query": {  
"match": {  
"message": {  
"query": "iso 9001",  
"type": "phrase"  
}  
}  
},  
"filter": {  
"term": { "\_type": "file" },  
"term": { "\_parent": "85164" }  
}  
}  
'

Here is my mapping code for 'file' types ( i am using elastica, a php api  
client, to generate these ):

$Files\_type = $this-\>Companies\_index-\>getType( 'file' );  
$Files\_mapping = new Elastica\_Type\_Mapping();  
$Files\_mapping-\>setType( $Files\_type );  
$Files\_mapping-\>setProperties(  
array(  
'content\_type' =\> array( 'type' =\> 'string', 'include\_in\_all' =\> FALSE ),  
'url' =\> array( 'type' =\> 'string', 'include\_in\_all' =\> FALSE ),  
'tier' =\> array( 'type' =\> 'integer' ),  
'is\_webpage' =\> array( 'type' =\> 'boolean', 'null\_value' =\> FALSE,  
'include\_in\_all' =\> FALSE ),  
'is\_product' =\> array( 'type' =\> 'boolean', 'null\_value' =\> FALSE,  
'include\_in\_all' =\> FALSE ),  
'is\_datasheet' =\> array( 'type' =\> 'boolean', 'null\_value' =\> FALSE,  
'include\_in\_all' =\> FALSE ),  
'title' =\> array( 'type' =\> 'string', 'boost' =\> 2.0 ),  
'description' =\> array( 'type' =\> 'string', 'boost' =\> 2.0 ),  
'keywords' =\> array( 'type' =\> 'string', 'boost' =\> 2.0 ),  
'h1\_tags' =\> array( 'type' =\> 'string', 'index\_name' =\> 'h1\_tag', 'boost'  
=\> 3.0 ), // array lists are pushed in here  
'h2\_tags' =\> array( 'type' =\> 'string', 'index\_name' =\> 'h2\_tag', 'boost'  
=\> 2.5 ), // array lists are pushed in here  
'h3\_tags' =\> array( 'type' =\> 'string', 'index\_name' =\> 'h3\_tag', 'boost'  
=\> 2.0 ), // array lists are pushed in here  
'anchor\_texts' =\> array(  
'type' =\> 'object',  
'properties' =\> array(  
'anchor\_text' =\> array(  
'type' =\> 'object',  
'properties' =\> array(  
'text' =\> array( 'type' =\> 'string', 'boost' =\> 10.0 ),  
'frequency' =\> array( 'type' =\> 'integer', 'index' =\> 'no',  
'include\_in\_all' =\> FALSE ),  
)  
)  
)  
),  
'url\_words' =\> array( 'type' =\> 'string', 'boost' =\> 2.0 ),  
'min\_price' =\> array( 'type' =\> 'float', 'index' =\> 'no', 'include\_in\_all'  
=\> FALSE ),  
'max\_price' =\> array( 'type' =\> 'float', 'index' =\> 'no', 'include\_in\_all'  
=\> FALSE ),  
'file' =\> array( 'type' =\> 'attachment' ),  
'images' =\> array(  
'type' =\> 'object',  
'index' =\> 'no',  
'include\_in\_all' =\> FALSE,  
'properties' =\> array(  
'image' =\> array(  
'type' =\> 'object',  
'properties' =\> array(  
'id' =\> array( 'type' =\> 'integer' ),  
'tier' =\> array( 'type' =\> 'integer' ),  
'extension' =\> array( 'type' =\> 'string' ),  
'entropy' =\> array( 'type' =\> 'float' ),  
)  
)  
)  
),  
'last\_processed' =\> array( 'type' =\> 'date', 'format' =\>  
'date\_time\_no\_millis', 'include\_in\_all' =\> FALSE, 'null\_value' =\> '' ),  
)  
); // end setProperties()  
$Files\_mapping-\>setParam( '\_parent', array( 'type' =\> 'company' ) );  
$Files\_mapping-\>setSource( array( 'excludes' =\> array( 'file' ) ) ); //  
prevents the file from being stored in the source  
$Files\_mapping-\>send();

--

---

<div class="post-metadata">

**Author:** ![tbrianjones](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbrianjones/32/1402_2.png) [@tbrianjones](https://discuss.elastic.co/u/tbrianjones)\
**Post date:** [December 7, 2012, 9:25pm UTC](https://discuss.elastic.co/t/phrase-match-with-filters/9961/2 "2012-12-07T21:25:37Z")

</div>

here is the solution:

{  
"query": {  
"match\_phrase": {  
"\_all": "adhesive tapes"  
}  
},  
"filter": {  
"term": {  
"\_type": "file",  
"\_parent": "43"  
}  
}  
}

--

---

<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:00am UTC](https://discuss.elastic.co/t/phrase-match-with-filters/9961/3 "2017-07-06T03:00:47Z")

</div>

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


