2013-10-27 192 views
1

我是elasticsearch的新手,設法使用river插件從我的mongodb集合中導入記錄集。首先,我想查詢「desc」字段,但只是不能設法得到查詢..不知道如果問題是由索引的定義方式驅動的..任何人都可以幫忙嗎?在彈性搜索Elasticsearch嵌套查詢

樣品記錄看起來像這樣

{ 
    "took": 2, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 107209, 
     "max_score": 1, 
     "hits": [ 
     { 
      "_index": "shiv", 
      "_type": "shiv", 
      "_id": "iG1eIzN7RGO7hFfxTlnLuA", 
      "_score": 1, 
      "_source": { 
       "_id": { 
        "$oid": "50901d7f485bf7bd1c000021" 
       }, 
       "brand": "", 
       "category": { 
        "$ref": "categories", 
        "$id": { 
        "$oid": "4fbd2221758cb11d14000174" 
        } 
       }, 
       "comments": [], 
       "count_comment": 0, 
       "count_fav": 2, 
       "count_hotness": 1.46, 
       "count_rekick": 0, 
       "count_share": 0, 
       "country": { 
        "$ref": "countries", 
        "$id": { 
        "$oid": "4fec98f7758cb18c6e0002c9" 
        } 
       }, 
       "currency": "pound", 
       "desc": "A men's automatic watch, this Seamaster Bond model features a Co-Axial escapement and date function. Its blue dial is teamed with a stainless steel case and bracelet for a look that's sporty and refined.", 
       "gender": "male", 
       "ident": "omega-seamaster-diver-bond-men-s-automatic-watch---ernest-jones-1351622015", 
       "img_url": "http://s7ondemand4.scene7.com/is/image/Signet/5735793?$detail$", 
       "lifestyles": [ 
        { 
        "$ref": "lifestyles", 
        "$id": { 
         "$oid": "508ff6ca485bf73112000060" 
        } 
        } 
       ], 
       "location": "United Kingdom", 
       "owner": { 
        "$ref": "accounts", 
        "$id": { 
        "$oid": "50742fd8485bf74b7a00213f" 
        } 
       }, 
       "price": 2400, 
       "store": "ernestjones.co.uk", 
       "tags": [ 
        "ernest-jones", 
        "bond" 
       ], 
       "timestamp_creation": 1351622015, 
       "timestamp_exp": 1356825600, 
       "timestamp_update": 1351622015, 
       "title": "Omega Seamaster Diver Bond men's automatic watch - Ernest Jones", 
       "url": "http%3A%2F%2Fwww.ernestjones.co.uk%2Fwebstore%2Fd%2F5735793%2Fomega%20seamaster%20diver%20bond%20men%27s%20automatic%20watch%2F%3Futm_source%3Dgooglebase%26utm_medium%3Dfeedmanager%26cm_mmc%3DFroogle-_-CKB-_-nurses_fobs-_-watches%26cm_mmca1%3Domega%26cm_mmca2%3Dmale%26cm_mmca3%3Dadult" 
      } 
     } 
     ] 
    } 
} 

索引「毒刃」的映射看起來像

{ 
    "shiv": { 
     "properties": { 
     "$oid": { 
      "type": "string" 
     } 
     } 
    } 
} 

再次感謝

+1

哪些查詢你有沒有試過到目前爲止? – mconlin

回答

0

lots of ways to query,你有沒有嘗試過匹配查詢?

使用curl或您所選擇的其他客戶端...
的http:// [主持人]:9200/[INDEX_NAME]/[DOC_TYPE]/_search

{ 
     "query" : { 
      "match" : { 
       "desc" : "some value you want to find in desc" 
      } 
     } 
    } 
+0

謝謝mconlin ..我已經嘗試過使用索引中存在的有效文本進行查詢,但不知何故,它總是給我返回零點擊。這是我得到的全部'{「take」:2,「timed_out」:false,「_ shards」:{「total」:5,「success」:5,「failed」:0},「hits」:{「total 「:0,」max_score「:null,」hits「:[]}} – user2925534

+0

您的查詢是否可以在複雜度較低的字段上工作?你可以搜索「性別」:「男性」嗎?你正在尋找合適的案例(上/下)。那些帶有特殊字符的長篇描述可以用奇怪的方式進行標記和分析。我會先用一個簡單的字段來檢查你的查詢語法。 – mconlin

+0

我已經嘗試使用大寫/小寫變體的所有字段,唯一可用的字段是ES _id。另外還有一個簡單的方法可以將數據重新索引到新索引(不同的映射/設置),而無需再次推送大文件?不確定映射是否導致問題,但不想花費數天的時間再次推送文件。 – user2925534