[英]How can I query elasticsearch for only one type of record?
我正在向elasticsearch發出一個查詢,我正在獲得多種記錄類型。 如何將結果限制為一種類型?
以下查詢將結果限制為類型為“your_type”的記錄:
curl - XGET 'http://localhost:9200/_all/your_type/_search?q=your_query'
有關詳細信息,請參閱http://www.elasticsearch.org/guide/reference/api/search/indices-types.html 。
您還可以使用查詢dsl過濾掉特定類型的結果,如下所示:
$ curl -XGET 'http://localhost:9200/_search' -d '{
"query": {
"filtered" : {
"filter" : {
"type" : { "value" : "my_type" }
}
}
}
}
'
版本6.1更新:類型過濾器現在替換為類型查詢: https : //www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html您可以在兩個查詢中使用它和過濾器上下文。
{
"query" : {
"filtered" : {
"filter" : {
"bool" : {
"must" :[{"term":{"_type":"UserAudit"}}, {"term" : {"eventType": "REGISTRATION"}}]
}
}
}
},
"aggs":{
"monthly":{
"date_histogram":{
"field":"timestamp",
"interval":"1y"
},
"aggs":{
"existing_visitor":{
"terms":{
"field":"existingGuest"
}
}
}
}
}
}
“_type”:“UserAudit”條件將查看僅特定於類型的記錄
在版本2.3
您可以查詢_type字段,如:
{
"query": {
"terms": {
"_type": [ "type_1", "type_2" ]
}
}
}
或者,如果要排除類型:
{
"query": {
"bool" : {
"must_not" : {
"term" : {
"_type" : "Hassan"
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.