search - Multiple Word Matches (Full Text) In single or multiple documents in Elasticsearch -
my requirement this:
if pass multiple words search list, es return documents subset of word matches along words matched can understand document matched subset.
suppose need search words such football, cricket, tennis, golf etc. in 3 documents
i going store these files in corresponding documents. mappings "mydocuments" index looks this:
{ "mydocuments" : { "mappings" : { "docs" : { "properties" : { "file_content" : { "type" : "string" } } } } } } first document
{ _id: 1, file_content: "i love tennis , cricket"} second document:
{ _id: 2, file_content: "tennis , football popular"} third document:
{ _id: 3, file_content: "football , cricket originated in england"} i should able search single file/or multiple files football, tennis, cricket, golf , should return this
something this
"hits":{ "total" : 3, "hits" : [ { "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_source" : { "file_content" : ["football","cricket"], "postdate" : "2009-11-15t14:12:12", } }, { "_index" : "twitter", "_type" : "tweet", "_id" : "2", "_source" : { "file_content" : ["football","tennis"], "postdate" : "2009-11-15t14:12:12", } } ] or in case of multiple file searches array of above search results
any idea how can using elasticsearch?
if can not done using elasticsearch ready evaluate other options (native lucene, solr)
edit
my bad did not provide enough details. @andrew meant file text content of file stored string field (full text) in document in es. assume 1 file corresponds 1 document text content string in field called "file_content".
the closest thing can want highlighting, meaning emphasizing searched terms in documents.
sample query:
{ "query": { "match": { "file_content": "football tennis cricket golf" } }, "highlight": { "fields": {"file_content":{}} } } result:
"hits": { "total": 3, "max_score": 0.027847305, "hits": [ { "_index": "test_highlight", "_type": "docs", "_id": "1", "_score": 0.027847305, "_source": { "file_content": "i love tennis , cricket" }, "highlight": { "file_content": [ "i love <em>tennis</em> , <em>cricket</em>" ] } }, { "_index": "test_highlight", "_type": "docs", "_id": "2", "_score": 0.023869118, "_source": { "file_content": "tennis , football popular" }, "highlight": { "file_content": [ "<em>tennis</em> , <em>football</em> popular" ] } }, { "_index": "test_highlight", "_type": "docs", "_id": "3", "_score": 0.023869118, "_source": { "file_content": "football , cricket originated in england" }, "highlight": { "file_content": [ "<em>football</em> , <em>cricket</em> originated in england" ] } } ] } as can see terms found highlighted (elements surrounded <em> tags) under special highlight section.
Comments
Post a Comment