# Cannot search my pdf files

**URL:** https://discuss.elastic.co/t/cannot-search-my-pdf-files/348297
**Category:** Elasticsearch
**Tags:** elastic-stack-sql
**Created:** [November 30, 2023, 7:10am UTC](https://discuss.elastic.co/t/cannot-search-my-pdf-files/348297 "2023-11-30T07:10:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mandy\_Poon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mandy_poon/32/123964_2.png) [@Mandy\_Poon](https://discuss.elastic.co/u/Mandy_Poon)
#### Post date: [November 30, 2023, 7:10am UTC](https://discuss.elastic.co/t/cannot-search-my-pdf-files/348297/1 "2023-11-30T07:10:49Z")

</div>

I have a pdf file and there is a wording "XXX Contract ID - 170458" on the pdf.  
However I cannot search my file if I use "Contract ID - 170458".  
(I can search the pdf file if I use "170458")

Anyone can help?

Thank you very much

// My code here

`````````````````````````````````````````````````````````````auto
get /contract_dms/_search
{
  "_source": ["file.*","highlight.*"],
  "query": {
    "query_string": {
      "query": "Contract ID - 170458",
       "default_operator": "AND",
       "fields": ["content"]
       
    }
  },
  "highlight": {
    "number_of_fragments": 4,
    "fragment_size": 100,
    "require_field_match": "true",
    "fields": {
      "content": {},
      "file.filename":{}
    }
  },
  "sort":[
    {"file.last_modified":{"order":"asc", "unmapped_type":"keyword"}}
  ],
  "size":50,
  "from":0
}
````````````````````````````````````````````````````````````
This category relates to the [Enterprise Search](https://www.elastic.co/enterprise-search) set of products - App Search, Site Search and Workplace Search.
If your question relates to core Elasticsearch functionality, please head over to the #elastic-stack:elasticsearch category for assistance.

*PS - Please delete this text before posting your topic*
`````````````````````````````````````````````````````````````

---

<div class="post-metadata">

### Author: ![ashishtiwari1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishtiwari1993/32/135241_2.png) [@ashishtiwari1993](https://discuss.elastic.co/u/ashishtiwari1993)
#### Post date: [December 1, 2023, 5:23am UTC](https://discuss.elastic.co/t/cannot-search-my-pdf-files/348297/2 "2023-12-01T05:23:14Z")

</div>

Hello @Mandy_Poon, Welcome to the Elastic community.

Could you please show mapping

```auto
GET contract_dms/_mapping

```

I think term is not created with whole string which you are looking for.

---

<div class="post-metadata">

### Author: ![nextgen](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@nextgen](https://discuss.elastic.co/u/nextgen)
#### Post date: [December 1, 2023, 7:44am UTC](https://discuss.elastic.co/t/cannot-search-my-pdf-files/348297/3 "2023-12-01T07:44:33Z")

</div>

> [@Mandy\_Poon](#):
>
> I have a pdf file and there is a wording "XXX Contract ID - 170458" on the pdf.  
> However I cannot search my file if I use "Contract ID - 170458".  
> (I can search the pdf file if I use "170458")
> 
> Anyone can help?
> 
> Thank you very much
> 
> // My code here
> 
> ```auto
> get /contract_dms/_search
> {
> "_source": ["file.*","highlight.*"],
> "query": {
> "query_string": {
> "query": "Contract ID - 170458",
> "default_operator": "AND",
> "fields": ["content"]
>        
> }
> },
> "highlight": {
> "number_of_fragments": 4,
> "fragment_size": 100,
> "require_field_match": "true",
> "fields": {
> "content": {},
> "file.filename":{}
> }
> },
> "sort":[
> {"file.last_modified":{"order":"asc", "unmapped_type":"keyword"}}
> ],
> "size":50,
> "from":0
> }
> 
> ```
> 
> This category relates to the [Enterprise Search](https://www.elastic.co/enterprise-search) set of products - App Search, Site Search and Workplace Search.  
> If your question relates to core Elasticsearch functionality, please head over to the #Elasticsearch category for assistance.
> 
> _PS - Please delete this text before posting your topic_
> 
> ```auto
> 
> ```

One potential issue could be how the content is indexed in Elasticsearch. It seems that the default operator is set to "AND" in your query. When using the "AND" operator, Elasticsearch will try to find documents that contain all the specified terms. In your case, "Contract ID - 170458" might not be present as a complete phrase in the content.

Here are a few suggestions you can try:

Use a Phrase Query:  
Change your query to a phrase query to search for the entire string as a phrase. Update your query to:

```auto

"query_string": {
  "query": "\"Contract ID - 170458\"",
  "default_operator": "AND",
  "fields": ["content"]
}

```

The double quotes around the query indicate that you want to search for the entire phrase.

Use a Match Query:  
Try using a match query instead, which is often more suitable for full-text search. Here's an example:

```auto
"match": {
  "content": "Contract ID - 170458"
}

```

This will search for documents where the entire phrase "Contract ID - 170458" is present in the content field.

Check Analyzer Settings:  
Ensure that the analyzer used during indexing and searching is not splitting the string in a way that makes it difficult to find. You may need to customize the analyzer settings to better suit your needs.

After making changes, reindex your content or update your existing documents accordingly. Keep in mind that the effectiveness of these suggestions may depend on your specific Elasticsearch mapping and analyzer configurations.

---

<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: [December 29, 2023, 7:45am UTC](https://discuss.elastic.co/t/cannot-search-my-pdf-files/348297/4 "2023-12-29T07:45:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
