# Encountering an Issue with Newly Created Index File in Elastic Search

**URL:** <https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 18, 2024, 6:40pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648 "2024-03-18T18:40:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 18, 2024, 6:40pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/1 "2024-03-18T18:40:41Z")

</div>

When reading the text data from a PDF document and saving it into the content field of an Elasticsearch document, I encountered an issue where the first saved index file did not return results when searched. However, creating a second index for the same file resulted in successful searches.

I am using C# to search the content using the MatchPhrase function for exact matches. I am seeking assistance to understand the root cause of this issue and how to resolve it.

#Elasticsearch

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [March 18, 2024, 7:31pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/2 "2024-03-18T19:31:08Z")

</div>

Hi @Dinesh_Raj ,

To clarify, you used two different indices for the same document, and one index was searchable, but the other was not?

Can you share:

- the mappings of each index
- the JSON source document you ingested into both indices
- the query you tried to use (let's eliminate the language client for now, please reproduce the query in `curl` or Kibana Dev Tools)

---

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 19, 2024, 4:27pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/3 "2024-03-19T16:27:47Z")

</div>

Hi @Sean_Story ,

Thank you for the quick response. Please find the comments for you requested details.

you used two different indices for the same document, and one index was searchable, but the other was not? – No, I’m using single indices for same the documents. The second set of documents is searchable, whereas the first set was not

Note : I’m using "content" field to search the data.

the mappings of each index -

```
* [{"mappings":{"properties":{"DocID":{"type":"integer"},"Number":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"Name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"content":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"contentList":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"documentID":{"type":"integer"},"documentName":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"documentSource":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"documentURL":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"iD":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}]

```

the JSON source document you ingested into both indices – I’m using single indices and sharing one document data

```
* {"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq"},"max_score":1,"hits":[{"_index":"esdocument_dev","_id":"qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28","_score":1,"_source":{"iD":"qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28","DocID":1111,"documentName":"Upload Document","content":"Page :1\r\nDineshraj elastic document 18-03-2024\n\r\n","documentURL":"Upload Document.pdf","Number":"1111-0000","Name":"TEST ES","documentSource":"OTHER_DOCUMENT","documentID":7}}]}}

```

the query you tried to use (let's eliminate the language client for now, please reproduce the query in curl or Kibana Dev Tools) - curl search query was tried and able to retrieve the both documents.

C# - I'm using NEST library version 7.175 and tested with first saved document getting no result and find screen shot for your reference.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/3/e396c29bb36929abf2ab0988f637a2afbecf3114.jpeg)

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [March 19, 2024, 7:46pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/4 "2024-03-19T19:46:41Z")

</div>

Hi @Dinesh_Raj ,

I think I'm having trouble understanding what your issue is, because you may be misusing some special terms.

"Index" in Elasticsearch is like a SQL table. "Document" is what we call a record in an Index.

> the first saved index file did not return results when searched. However, creating a second index for the same file resulted in successful searches.  
> ...  
> No, I’m using single indices for same the documents. The second set of documents is searchable, whereas the first set was not

So 👆 does not make a lot of sense.

Based on your more recent response, it sounds like you have a single index, with two documents. One of those documents shows up in your search results, the other does not. Is this correct? I'm still confused because you call them "the first set of documents" and "the second set of documents" which makes it sound like more than one document in each "set".

In your paste, you only shared one document. I've reformatted for readability:

```auto
      {
        "_index": "esdocument_dev",
        "_id": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28",
        "_score": 1,
        "_source": {
          "iD": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28",
          "DocID": 1111,
          "documentName": "Upload Document",
          "content": "Page :1\r\nDineshraj elastic document 18-03-2024\n\r\n",
          "documentURL": "Upload Document.pdf",
          "Number": "1111-0000",
          "Name": "TEST ES",
          "documentSource": "OTHER_DOCUMENT",
          "documentID": 7
        }
      }

```

You also shared the mappings (also reformatted here for readability)

```auto
{
    "mappings": {
      "properties": {
        "DocID": {
          "type": "integer"
        },
        "Number": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "Name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "content": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "contentList": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "documentID": {
          "type": "integer"
        },
        "documentName": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "documentSource": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "documentURL": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "iD": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }

```

Please share share _both_ documents (or sets of documents) that you are trying to search, AND the elasticsearch query you are executing. Please do NOT send a screenshot/paste of C# code. It will be more helpful to first troubleshoot with a pure JSON REST API (curl or Kibana Dev Tools) and _then_ we can make sure to translate to c#.

---

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 20, 2024, 3:15pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/5 "2024-03-20T15:15:07Z")

</div>

Hi @Sean_Story

Based on your more recent response, it sounds like you have a single index, with two documents. One of those documents shows up in your search results, the other does not. Is this correct? - **Yes, Correct**.

I have used only one index which has mapping mentioned below.

```auto
{
    "mappings": {
      "properties": {
        "DocID": {
          "type": "integer"
        },
        "Number": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "Name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "content": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "contentList": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "documentID": {
          "type": "integer"
        },
        "documentName": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "documentSource": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "documentURL": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "iD": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }

```

**Document which I have inserted**

```auto
{
        "_index": "esdocument_dev",
        "_id": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28",
        "_score": 1,
        "_source": {
          "iD": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28",
          "DocID": 1111,
          "documentName": "Upload Document",
          "content": "Page :1\r\nDineshraj elastic document 18-03-2024\n\r\n",
          "documentURL": "Upload Document.pdf",
          "Number": "1111-0000",
          "Name": "TEST ES",
          "documentSource": "OTHER_DOCUMENT",
          "documentID": 7
        },
	{
        "_index": "esdocument_dev",
        "_id": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq29",
        "_score": 1,
        "_source": {
          "iD": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq29",
          "DocID": 1111,
          "documentName": "Upload Document",
          "content": "Page :1\r\nDineshraj elastic document 18-03-2024\n\r\n",
          "documentURL": "Upload Document.pdf",
          "Number": "1111-0000",
          "Name": "TEST ES",
          "documentSource": "OTHER_DOCUMENT",
          "documentID": 7
        }

```

**Curl command Query :**

```auto
curl -X POST "https://development.com/elastic/esdocument_dev/_search" -u elastic -H 'Content-Type: application/json' -d '{
  "query": {
    "match_phrase": {
      "content": "Dineshraj"
    }
  }
}'

```

For the above query, I'm getting both document as **result below**.

```auto
{
    "took": 3,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 0.6533776,
        "hits": [
            {
                "_index": "esdocument_dev",
        "_id": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28",
        "_score": 1,
        "_source": {
          "iD": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq28",
          "DocID": 1111,
          "documentName": "Upload Document",
          "content": "Page :1\r\nDineshraj elastic document 18-03-2024\n\r\n",
          "documentURL": "Upload Document.pdf",
          "Number": "1111-0000",
          "Name": "TEST ES",
          "documentSource": "OTHER_DOCUMENT",
          "documentID": 7
                }
            },
            {
               "_index": "esdocument_dev",
        "_id": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq29",
        "_score": 1,
        "_source": {
          "iD": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq29",
          "DocID": 1111,
          "documentName": "Upload Document",
          "content": "Page :1\r\nDineshraj elastic document 18-03-2024\n\r\n",
          "documentURL": "Upload Document.pdf",
          "Number": "1111-0000",
          "Name": "TEST ES",
          "documentSource": "OTHER_DOCUMENT",
          "documentID": 7
                }
            }
        ]
    }
}

```

I have a specific scenario where I'm querying Elasticsearch for documents based on the content field using the "match\_phrase" operator with the text "Content":"Dineshraj". When I perform this query using a curl command, I'm getting both expected documents as results. However, when I execute the same query using the C# NEST library,  
I'm only receiving one document as a result( **`"_id": "qqqqqqqqq85-159a-qqqq-a1cc-qqqqqq29"`** ).

```auto
string searchKey = "Dineshraj";
var searchResponse = ElasticConnectionString.EsClient().Search<DocumentMetadata>(s => s
                            .From(from)
                            .Size(size)
                            .Index("esdocument_dev")
                            .Query(q => q
                             .MatchPhrase(m => m
                                .Field(f => f.Content)
                                .Query(searchKey)
                                 )
                            )
                        );

```

I would appreciate your assistance in resolving this discrepancy. Could you please investigate **why I'm not getting both documents in the C# NEST library search response?** If there are any known issues or solutions related to the C# library, please redirect me to the relevant team or resources.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 20, 2024, 8:32pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/6 "2024-03-20T20:32:01Z")

</div>

What are the from and size parameters you are specifying set to? These seem to be in addition to the example you used in the dev console that worked.

---

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 21, 2024, 6:37am UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/7 "2024-03-21T06:37:45Z")

</div>

Hi @Christian_Dahlqvist ,

I'm used parameter values and logic mentioned below.

```auto
int pageNo = 1;
int pageSize = 100;
int from = (pageNo - 1) * pageSize + 1;
string searchKey = "Dineshraj";
int size = pageNo * pageSize;
var searchResponse = ElasticConnectionString.EsClient().Search<DocumentMetadata>(s => s
                            .From(from)
                            .Size(size)
                            .Index("esdocument_dev")
                            .Query(q => q
                             .MatchPhrase(m => m
                                .Field(f => f.Content)
                                .Query(searchKey)
                                 )
                            )
                        );

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 21, 2024, 6:48am UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/8 "2024-03-21T06:48:18Z")

</div>

It looks like `from` will be set to `1`, which I believe will exclude the first match. Try using the default value of `0` and see if that fixes your issue.

---

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 21, 2024, 7:10am UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/9 "2024-03-21T07:10:43Z")

</div>

Hi @Christian_Dahlqvist ,

Thank you for the quick response.

I have set as from value of 0 then no documents are getting. If set as 1 then getting only one documents.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 21, 2024, 7:12am UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/10 "2024-03-21T07:12:11Z")

</div>

> [@Dinesh\_Raj](#):
>
> ```auto
> .From(from)
> .Size(size)
> 
> ```

What if you try removing these parameters and rely on the defaults? You could also add `from` and `size` settings to the query you run in the dev console and see what difference it may make there.

---

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 21, 2024, 7:33am UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/11 "2024-03-21T07:33:02Z")

</div>

Hi @Christian_Dahlqvist ,

Sorry for delayed response. If I remove those items, I'm getting both result. Thank you.

In my business case, the frontend server-side table binding displays records from 1 to 100 on the first page, and the next page shows records from 101 to 200. How can I achieve this if I remove those items?

Note : Real-time documents contain a large number of records.

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [March 21, 2024, 7:56am UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/12 "2024-03-21T07:56:54Z")

</div>

Hi there!

I think your from/size calculation is just a little bit off. Like mentioned, the first page should be `0`. But in this case, your code sets `from` to `(0 - 1) * 100 + 1 = -99` which obviously is not correct.

You as well set `size = pageNo * pageSize` which means on page 0 you get 0 results, on page 1 you get 100 results, on page 2 you get 200 results, ...

Just try:

```auto
var from = pageNo * pageSize;
var size = pageSize;

```

---

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 21, 2024, 8:12am UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/13 "2024-03-21T08:12:26Z")

</div>

Hi @flobernd ,

Thanks for the response. I will check and confirm on asap.

---

<div class="post-metadata">

**Author:** ![Dinesh\_Raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_raj/32/132748_2.png) [@Dinesh\_Raj](https://discuss.elastic.co/u/Dinesh_Raj)\
**Post date:** [March 21, 2024, 6:15pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/14 "2024-03-21T18:15:05Z")

</div>

Hi @Christian_Dahlqvist & @flobernd ,

Your support has been invaluable. I've revised the logic for the 'from' value, and now everything is functioning flawlessly. I'm pleased to report that I'm receiving both documents as expected.

---

<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:** [April 18, 2024, 6:15pm UTC](https://discuss.elastic.co/t/encountering-an-issue-with-newly-created-index-file-in-elastic-search/355648/15 "2024-04-18T18:15:52Z")

</div>

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