2013-08-27 19 views
0

我最近在維基百科河中安裝了ElasticSearch,因爲我正在處理包含文章標題的自動填充框。我一直在試圖找出查詢數據集的最佳方式。以下作品:如何使用GET過濾ElasticSearch中的字段

/wikipedia/_search?q=mysearch&fields=title,redirect&size=20 

,但我想更多的約束添加到搜索:

disambiguation=false, redirect=false, stub=false, special=false 

我是新來ElasticSearch和文檔已經不遠得到我。從我讀過的內容中我需要一個過濾的查詢;有沒有辦法做到這一點從GET請求?這將使我的具體用例更容易。如果不是,POST請求將如何顯示?提前致謝。

僅供參考,映射是:

{ 
    "wikipedia": { 
    "page": { 
     "properties": { 
     "category": { 
      "type": "string" 
     }, 
     "disambiguation": { 
      "type": "boolean" 
     }, 
     "link": { 
      "type": "string" 
     }, 
     "redirect": { 
      "type": "boolean" 
     }, 
     "special": { 
      "type": "boolean" 
     }, 
     "stub": { 
      "type": "boolean" 
     }, 
     "text": { 
      "type": "string" 
     }, 
     "title": { 
      "type": "string" 
     } 
     } 
    } 
    } 
} 

回答

1

增加更多的限制,你可以使用Lucene的語法繼續做這樣的事情:

/wikipedia/_search?q=mysearch AND disambiguation:false AND redirect:false AND stub:false AND special:false&fields=title,redirect&size=20 

爲了提高您可以通過使用過濾器的性能json API,查詢將如下所示:

curl -XGET 'http://localhost:9200/wikipedia/_search?pretty=true' -d ' 
{ 
    "from" : 0, 
    "size" : 20, 
    "query":{ 
     "filtered" : { 
      "query" : { 
       "text" : { "title" : "test" } 
      }, 
      "filter" : { 
       "and": [ 
        { 
         "term" : { 
          "stub" : false 
         } 
        }, 
        { 
         "term" : { 
          "disambiguation" : false 
         } 
        }, 
        { 
         "term" : { 
          "redirect" : false 
         } 
        }, 
        { 
         "term" : { 
          "special" : false 
         } 
        } 
       ] 
      } 
     } 
    } 
} 
' 
+0

謝謝,正是我在找的東西。 – soulkphp

+0

任何想法如何添加限制?無論在哪裏添加限制,似乎都會顯示10個結果。我正在使用你的後一個建議。謝謝! – soulkphp

+0

我使用可用於限制結果數量的參數編輯帖子。 – moliware

相關問題