# Search using term on Next 7.6.1 not returning any result

**URL:** <https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687>\
**Category:** Elasticsearch\
**Created:** [March 30, 2020, 1:49pm UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687 "2020-03-30T13:49:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shahed\_Aziz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahed_aziz/32/65311_2.png) [@Shahed\_Aziz](https://discuss.elastic.co/u/Shahed_Aziz)\
**Post date:** [March 30, 2020, 1:49pm UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687/1 "2020-03-30T13:49:59Z")

</div>

Hi,

I inserted some data to an index. To search on that, when I use match all, I can see my data.

` var temp = _elasticClient.SearchAsync<MyDocument>(s => s.MatchAll(), cancellationToken);`

But when I search using term, i dont get any hit.

```auto
    var result = await _elasticClient.SearchAsync<MyDocument>(s => s
        .Query(q => q
            .Term(p => p.Id, "aa22")), cancellationToken);

```

Any help to point out my mistake will be much appreciated.

Kind regards,

Shahed

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 31, 2020, 6:22am UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687/2 "2020-03-31T06:22:13Z")

</div>

What does the mapping look like in the inferred index for `MyDocument`?

A common reason for a search not returning the results expected is because of a difference in how the input for a field at document index time is analyzed, compared to how the query input for a field is analyzed at query time.

In this case, a `term` query does not undergo analysis; that is, the query is looking for the exact term `"aa22"` in the id field. If the id field is mapped as a `"text"` field, the document field will be analyzed at document index time, so the terms that result from analysis and are stored in the inverted index for the id field may not be a match for the term `"aa22"`. Take a look at the [documentation on analysis](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html) for more information.

---

<div class="post-metadata">

**Author:** ![Shahed\_Aziz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahed_aziz/32/65311_2.png) [@Shahed\_Aziz](https://discuss.elastic.co/u/Shahed_Aziz)\
**Post date:** [March 31, 2020, 9:12am UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687/3 "2020-03-31T09:12:08Z")

</div>

Hi, thank you for the explanation. It does make sense and I will read the analysis documentation.  
`MyDocument` looks like this

```auto
    public class MyDocument
    {
        public string Id { get; set; }
        public string DocNumber { get; set;}
    }

```

I did not do any manual mapping. So the filed Id will be mapped as text.  
When I write my query with `QueryString` instead of term, then I get the expected result.

```auto
var searchQuery = Query<MyDocument >.QueryString(c => c
                .Query("aa22")
                .DefaultField(p => p.Id)
                .DefaultOperator(Operator.And));

            var response = _elasticClient.Search<MyDocument >(s => s
                .Query(x => x.Bool(q => q.Must(searchQuery))));

```

I guess that confirms what you mentioned.

---

<div class="post-metadata">

**Author:** ![Shahed\_Aziz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahed_aziz/32/65311_2.png) [@Shahed\_Aziz](https://discuss.elastic.co/u/Shahed_Aziz)\
**Post date:** [March 31, 2020, 9:17am UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687/4 "2020-03-31T09:17:46Z")

</div>

In my search, for some text field, I need strict exact match and for some other text fields, I need partial to complete match. Can you please suggest how can I achieve that indexing and mapping using code?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 31, 2020, 10:55pm UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687/5 "2020-03-31T22:55:38Z")

</div>

> [@Shahed\_Aziz](#):
>
> In my search, for some text field, I need strict exact match and for some other text fields, I need partial to complete match. Can you please suggest how can I achieve that indexing and mapping using code?

How to map fields to enable the kinds of full-text search that users will perform is a large topic requiring an understanding of the problem domain.

As some general advice, if `Id` is only ever going to be search for **exact** matches, map it as a [`keyword` field mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html). For string fields that would require full-text search, map them as [`text` field mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html); `text` field mappings will use the standard analyzer by default, but you can configure different analysis to suit your needs. Check out the documentation for the client that covers both [mapping](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/mapping.html) and [analysis](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/analysis.html).

---

<div class="post-metadata">

**Author:** ![Shahed\_Aziz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahed_aziz/32/65311_2.png) [@Shahed\_Aziz](https://discuss.elastic.co/u/Shahed_Aziz)\
**Post date:** [April 1, 2020, 8:58am UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687/6 "2020-04-01T08:58:18Z")

</div>

Thank you so much for the suggestions. I went through the analyzer and rest of the documentation and have a better idea about this now. What you suggested makes complete sense. Thank you. Really appreciate.

---

<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 29, 2020, 8:58am UTC](https://discuss.elastic.co/t/search-using-term-on-next-7-6-1-not-returning-any-result/225687/7 "2020-04-29T08:58:26Z")

</div>

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