2016-11-25 185 views
0

我試圖尋找到處處尋找答案,但我一直沒有找到它的成功。我有一個簡單的索引中,我使用下面的查詢使用者去取一些成果:嵌套查詢|彈性搜索

1. curl -XGET 'localhost:9200/users/_search?pretty' -d' 
{ 
"explain": true, 
"query": { 
"match": { 
    "skills": { 
    "query": "im looking for some business counseling", 
    "operator": "or", 
    "fuzziness": "auto", 
    "analyzer": "search_analyzer" 
    } 
    } 
}, 
"sort": [ 
{"_score": "desc"} 
], 
}' 

該查詢成功地給我結果,我已經丟失是關於如何使用所需的...現在的部分以下查詢(#2)查詢剛從上面的查詢(#1)中提取的文檔。 (順便說一句我一直在使用從elastic.co文檔中找到的所有類型的複合查詢的嘗試,但問題是,他們只查詢一組文件根據不同的標準還是我錯了?):

2. "query": { 
"match": { 
    "search": { 
    "query": "now I want to query the documents just fetched with this text", 
    "operator": "or", 
    "fuzziness": "auto", 
    "analyzer": "search_analyzer" 
    } 
} 
} 
+0

爲什麼你想讓這些東西按照特定的順序運行嗎? –

+0

我想這樣做的原因是因爲我想做一些交叉匹配 –

回答

0

所以通過文檔挖後再次我最終找到與該化合物布爾查詢的答案......它看起來像這樣:

curl -XGET 'localhost:9200/users/_search?pretty' -d' 
{ 
"explain": true, 
    "query": { 
    "bool": { 
    "should": [ 
    { "match": { "skills": "Im looking for somebody with business skills"}}, 
    { "bool": { 
     "should": [ 
     { "match": { "search": "someone is looking for my skills which are cooking,caking, and entertaining" }} 
     ] 
     }} 
    ] 
    } 
}, 
"sort": [ 
{"_score": "desc"} 
] 
}' 

隨着指數的映射看起來像這樣:

{ 
"settings": { 
    "analysis": { 
     "analyzer": { 
      "search_analyzer": { 
      "type": "custom", 
       "tokenizer": "punctuation", 
       "filter": ["lowercase","apostrophe","asciifolding","stop_analyzer","kstem"] 
      } 
     }, 
     "tokenizer": { 
      "punctuation": { 
       "type": "pattern", 
       "pattern": "[ .,!?+&@=-]" 
      } 
     }, 
     "filter": { 
      "stop_analyzer": { 
       "type": "stop" 
      } 
     } 
    } 
}, 
"mappings": { 
     "users": { 
      "properties": { 
       "skills": { 
        "type": "string", 
        "norms": { "enabled": false }, 
        "analyzer": "search_analyzer" 
       }, 
       "search": { 
        "type": "string", 
        "norms": { "enabled": false }, 
        "analyzer": "search_analyzer" 
       } 
      } 
     } 
    } 
}