scala - Searching for whole URL using elastic4s -
i'm using elastic4s in order index , search data in es. part of document i'm storing contains url field need search (the entire url). problem occurs when search document containing url field , 0 results.
for purpose of search define mapping ahead of inserting data index:
client.execute { create index <my_index> mappings { <my_type> { "url" typed stringtype analyzer notanalyzed } } }
i'm inserting data:
client.execute { index <my_index> -> <my_type> fields ( "url" -> "http://sample.com" ) }.await
and search documents:
val filter = """ |{ | "filtered" : { | "query" : { | "match_all" : {} | }, | "filter" : { | "bool" : { | "should" : [ | { "bool" : { | "must" : [ | { "term" : { "url" : "http://sample.com" } } | ] | } } | ] | } | } | } |} """.stripmargin client.execute { search in <my_index> -> <my_type> rawquery { filter } }.await
i 0 results after executing query. doing wrong?
thanks!
problem solved.
in mapping, instead of doing:
client.execute { create index <my_index> mappings { <my_type> { "url" typed stringtype analyzer notanalyzed } } }
i should have done:
client.execute { create index <my_index> mappings { <my_type> { "url" typed stringtype index "not_analyzed" } } }
or
client.execute { create index <my_index> mappings { <my_type> { "url" typed stringtype index notanalyzed } } }
Comments
Post a Comment