ElasticSearch: Labelling documents with matching search term -


i'm using elasticsearch 1.7 , in need of way label documents part of query_string query match.

i've been experimenting highlighting, found gets bit messy cases. i'd love have document tagged matching search terms.

here query i'm using: ( note ruby hash later gets encoded json )

{   query: {     query_string: {       fields: ["title^10", "keywords^4", "content"],       query: query_string,       use_dis_max: false     }   },   size: 20,   from: 0,   sort: [     { pub_date: { order: :desc }},     { _score:   { order: :desc }}   ] } 

the query_string variable based off user followed topics , might this: "(the , walking , dead) or (iphone) or (video , games)"

is there option can use documents returned have property matching search term the walking dead or (the , walking , dead)

if you're ready switch using bool/should queries, can split match on each field , use named queries, in results you'll name of query matched.

it goes this: in bool/should query, add 1 query_string query per field , name query identify field (e.g. title_query title field, etc)

{   "query": {     "bool": {       "should": [         {           "query_string": {             "fields": [               "title^10"             ],             "query": "query_string",             "use_dis_max": false,             "_name": "title_query"           }         },         {           "query_string": {             "fields": [               "keywords^4"             ],             "query": "query_string",             "use_dis_max": false,             "_name": "keywords_query"           }         },         {           "query_string": {             "fields": [               "content"             ],             "query": "query_string",             "use_dis_max": false,             "_name": "content_query"           }         }       ]     }   } } 

in results, you'll below _source array called matched_queries contains name of query matched returned document.

"_source": {     ... }, "matched_queries": [     "title_query" ], 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -