0

I am getting stuck getting while implementing search using elastic search nest. I have to implement like query with elastic search. for ex. select * from table where username like '%abc xyz%' As you can see in above sql query I have applied like query with string "abc" space and another string "xyz". Similarly I want this query in elastic search. Can anyone help me to implement such query in elastic search nest?

Below is the query

Client.Search<Video>(s => s
    .Query(q => q
        .Match(m => m
            .OnField("video_parent")
            .Query("0")
        ) && q
        .Match(m => m
            .OnField("video_status")
            .Query(objVideosFilterCriteria.Vide‌​oStatus.ToString())
        ) && q
        .MatchPhrase(ff=>ff
            .OnField("video_title")
            .Query(objVideosF‌​ilterCriteria.Search‌​String)
        ) && q
        .Range(r => r
            .OnField(f => f.video_date)
            .GreaterOrEquals(fromDate)
            .LowerOrEquals(toDate‌​)
        ) 
    )
    .From(objVideosFilterCriteria.PageIndex)
    .Size(objVideosFilt‌​erCriteria.PageSize)
‌​); 

Above is the query I am using. In this query I am using

q.MatchPhrase(ff=>ff
    .OnField("video_title")
    .Query(objVideosF‌​‌​ilterCriteria.Sear‌​ch‌​String)
) 

for like query. But it doesn't seem to work. I am using below data set and want to filter data from below list.

"hits" : [
  {       
    "_source" : {
      "video_id" : 265006,
      "video_title" : "nunchuk rockin roller II"
    }
  },

  {        
    "_source" : {
      "video_id" : 265013,
      "video_title" : "?Shaggy?????Locks???7??????Alberto E. Interview {407} 967 ~ 8596?"
    }
  },
  {        
    "_source" : {
      "video_id" : 265014,
      "video_title" : "Shakin' Stevens - Kalundborg Rocker"
    }
  },
  {       
    "_source" : {
      "video_id" : 265019, 
      "video_title" : "?Shaggy?????Locks? = 7??????Greg M. Interview {407} 967 ~ 8596?"
    }
  },
  {       
    "_source" : {
      "video_id" : 265023, 
      "video_title" : "?Shaggy?????Locks? = 7??????Jason M. Interview {407} 967 ~ 8596?"
    }    
  }

]

For example I would like to search with the keyword "kin rol" in the "video_title" field so with the above data it should fetch one record which exists at first position in above list but in my current query I am getting. nothing.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Vipin Rathore
  • 148
  • 1
  • 9

0 Answers0