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


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
               .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)
                                   //.MinimumShouldMatch(new MinimumShouldMatch("75%")))
               && q.DateRange(dr => dr.Field(f => f.Pubdate).GreaterThanOrEquals(StartDate).LessThanOrEquals(EndDate))

(Loren Siebert) #2

Kibana uses a QueryString query, and executes across all fields by default.


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

(Loren Siebert) #4

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.


@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

(Loren Siebert) #6

To have recent dates bring the score higher and older dates bring the score lower, look at the Function Score Query. The very first example in Decay Functions 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.

(system) #7

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