# What search query is being used when I look for text using kibana?

**URL:** <https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373>\
**Category:** Elasticsearch\
**Created:** [May 17, 2018, 5:19pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373 "2018-05-17T17:19:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![subrato](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@subrato](https://discuss.elastic.co/u/subrato)\
**Post date:** [May 17, 2018, 5:19pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373/1 "2018-05-17T17:19:39Z")

</div>

I have written some code that should look for text and return results from Elastic Search. Search looks at multiple fields. The results don't match to what I get if I search for the same text in kibana. So I am trying to understand how my code is different than what happens in kibana. Any ideas? Here is my code to search

```
     mediaResponse = elastic.Search<Articles>(s => s
               .Explain(true)
               .Pretty(true)
               .Human(true)
               .Index(mediaIndexName)
               .Type(mediaTypeName)
               .From(pageNumber)
               .Size(numResults)
               .Query(q => q
               .Bool(b => b
                        .Must(m => m
                                .MultiMatch(mm => mm.Fields
                                   (
                                       f => f
                                           .Field(fn => fn.Title)
                                           .Field(fn => fn.Content)
                                           .Field(fn => fn.Description)
                                   )
                                   .Query(queryTxt))))
                                   //.MinimumShouldMatch(new MinimumShouldMatch("75%")))
               && q.DateRange(dr => dr.Field(f => f.Pubdate).GreaterThanOrEquals(StartDate).LessThanOrEquals(EndDate))
            ));
```

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [May 17, 2018, 7:08pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373/2 "2018-05-17T19:08:51Z")

</div>

Kibana uses a [QueryString](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) query, and executes across all fields by default.

---

<div class="post-metadata">

**Author:** ![subrato](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@subrato](https://discuss.elastic.co/u/subrato)\
**Post date:** [May 17, 2018, 8:09pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373/3 "2018-05-17T20:09:08Z")

</div>

@loren Is that the right way to execute a search query? I assumed multimatch is the way to do it.

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [May 17, 2018, 9:33pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373/4 "2018-05-17T21:33:37Z")

</div>

There's no one right way to write the query. It totally depends on your use case. But if you want it to behave like Kibana, I think you need to use a QueryString query.

---

<div class="post-metadata">

**Author:** ![subrato](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@subrato](https://discuss.elastic.co/u/subrato)\
**Post date:** [May 17, 2018, 10:10pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373/5 "2018-05-17T22:10:39Z")

</div>

@loren Thanks for the reply. I am just learning as much as I can so would appreciate if you guide me a little bit. We have a lot of text content and basically its similar to what it would look like say if you go to tech crunch which has lot of text data and someone searches for wi-fi and it should return related data from content (body), title or summary.

I assumed a multi match would be the best approach but when I use that and sort it using dates, top results sometimes have null scores but if I remove the sort it will return results from say 10 years ago which might be irrelevant. How would I approach this kind of situation?

TIA @loren

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [May 17, 2018, 11:35pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373/6 "2018-05-17T23:35:29Z")

</div>

To have recent dates bring the score higher and older dates bring the score lower, look at the [Function Score Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html). The very first example in [Decay Functions](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-decay) does just this.

When you apply your own sort (e.g., date, name, etc), you are telling Elasticsearch not to care about its own scoring efforts.

---

<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:** [June 14, 2018, 11:35pm UTC](https://discuss.elastic.co/t/what-search-query-is-being-used-when-i-look-for-text-using-kibana/132373/7 "2018-06-14T23:35:37Z")

</div>

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