I am issuing a query to elasticsearch and I am getting multiple record types. How do I limit the results to one type?
我正在向elasticsearch发出一个查询,我正在获得多种记录类型。如何将结果限制为一种类型?
4 个解决方案
#1
21
The following query will limit results to records with the type "your_type":
以下查询将结果限制为类型为“your_type”的记录:
curl - XGET 'http://localhost:9200/_all/your_type/_search?q=your_query'
curl - XGET'http:// localhost:9200 / _all / your_type / _search?q = your_query'
See http://www.elasticsearch.org/guide/reference/api/search/indices-types.html for more details.
有关详细信息,请参阅http://www.elasticsearch.org/guide/reference/api/search/indices-types.html。
#2
14
You can also use query dsl to filter out results for specific type like this:
您还可以使用查询dsl过滤掉特定类型的结果,如下所示:
$ curl -XGET 'http://localhost:9200/_search' -d '{
"query": {
"filtered" : {
"filter" : {
"type" : { "value" : "my_type" }
}
}
}
}
'
#3
3
{
"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" condition will look the records only specific to type
“_type”:“UserAudit”条件将查看仅特定于类型的记录
#4
0
On version 2.3
you can query _type field like:
在版本2.3上,您可以查询_type字段,如:
{
"query": {
"terms": {
"_type": [ "type_1", "type_2" ]
}
}
}
Or if you want to exclude a type:
或者,如果要排除类型:
{
"query": {
"bool" : {
"must_not" : {
"term" : {
"_type" : "Hassan"
}
}
}
}
}
#1
21
The following query will limit results to records with the type "your_type":
以下查询将结果限制为类型为“your_type”的记录:
curl - XGET 'http://localhost:9200/_all/your_type/_search?q=your_query'
curl - XGET'http:// localhost:9200 / _all / your_type / _search?q = your_query'
See http://www.elasticsearch.org/guide/reference/api/search/indices-types.html for more details.
有关详细信息,请参阅http://www.elasticsearch.org/guide/reference/api/search/indices-types.html。
#2
14
You can also use query dsl to filter out results for specific type like this:
您还可以使用查询dsl过滤掉特定类型的结果,如下所示:
$ curl -XGET 'http://localhost:9200/_search' -d '{
"query": {
"filtered" : {
"filter" : {
"type" : { "value" : "my_type" }
}
}
}
}
'
#3
3
{
"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" condition will look the records only specific to type
“_type”:“UserAudit”条件将查看仅特定于类型的记录
#4
0
On version 2.3
you can query _type field like:
在版本2.3上,您可以查询_type字段,如:
{
"query": {
"terms": {
"_type": [ "type_1", "type_2" ]
}
}
}
Or if you want to exclude a type:
或者,如果要排除类型:
{
"query": {
"bool" : {
"must_not" : {
"term" : {
"_type" : "Hassan"
}
}
}
}
}