elasticsearch - How to fetch 2 or more docs if a query matches at least once in the doc? -
elasticsearch - How to fetch 2 or more docs if a query matches at least once in the doc? -
i new elasticsearch. there way write queries match , list out documnents matches available fields including mutual ones?
i'll seek set example.
i have  scheme based on criteria give out recommendations. graph. eg: starting product, osname, architecture(machine), release, version & on. 1st match product , osname  mutual search. later search if architecture x86 if true,  add together doc result & if release of service pack 1  add together   1 time again result. @ end, result should contain both 3 & 4 docs both has  mutual fields product , osname , 1 of query matches phrase "service pack 1" , other matces "x86"
below 2 of recommendations if query satisfies criteria give doc. below doc has product & osname mutual fields.
put /support/recommendation/3 {     "recommendation":"suggested architecture 64 bit",     "type":"warning",     "criteria": {         "product": ["tar","zip"],         "osname": "windows",         "machine": "x86"         }    }  set /support/recommendation/4 {     "recommendation":"service pack 2 or more needed",     "type":"error",     "criteria": {         "product": ["tar","zip"],         "osname": "windows",         "release": "service pack 1"     }    }    my query
get /support/recommendation/_search {   /*search tar, windows, 32bit(x86) & sp1*/     "query": {         "filtered" : {             "query": {                 "bool"   : {                     "must": [                        {"match": {                           "product": "tar"                        }                        },                        {"match": {                           "osname": "windows"                        }                                       }                     ],                     "must": [                        {"match_phrase": {                           "release": "service pack 1"                        }}                     ],                      "should": [                        {"match": {                             "machine": "x86"                        }                                       }                     ]                 }             }                     }     } }          is there way accomplish this?
if want docs in result if match either machine: x86 or release: service pack 1, utilize should clause including both.
get /support/recommendation/_search {   /*search tar, windows, 32bit(x86) & sp1*/     "query": {         "filtered" : {             "query": {                 "bool"   : {                     "must": [                        {"match": {                           "product": "tar"                        }                        },                        {"match": {                           "osname": "windows"                        }                                       }                     ],                     "should": [                        {"match": {                             "machine": "x86"                           }                                       },                        {"match_phrase": {                           "release": "service pack 1"                        }                       }                     ],                    "minimum_should_match" : 1                 }             }                     }     } }    update: added minimum_should_match clause
 elasticsearch 
 
Comments
Post a Comment