【问题标题】:Elasticsearch Facets: Search on _index returned no resultsElasticsearch Facets:在 _index 上搜索未返回任何结果
【发布时间】:2014-11-21 12:28:13
【问题描述】:

我想按index->​​按index_type->文本搜索数据这个顺序在ES上搜索数据。
当我在“_index”上使用以下查询时,我希望获得该特定 _index 下的 index_types 列表以及相关数据,但它什么也没返回。另一方面,当我通过 _type 搜索时,我得到了与 index_type 相关的数据。我哪里出错了?

curl -XGET 'http://localhost:9200/_all/_search?pretty' -d '{
      "facets": {
        "terms": {
          "terms": {
            "field": "_index",
            "size": 10,
            "order": "count",
            "exclude": []
          },
          "facet_filter": {
            "fquery": {
              "query": {
                "filtered": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "query_string": {
                            "query": "*"
                          }
                        }
                      ]
                    }
                  },
                  "filter": {
                    "bool": {
                      "must": [
                        {
                          "terms": {
                            "_index": [
                              "<index_name>"
                            ]
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "size": 0
    }'

注意:我首先在 Kibana 上遇到了这个问题,在那里我使用了过滤器 "_index":"name_of_index";它没有返回任何结果,但 "_type":"name_of_index_type" 返回了预期的结果。我发现 Kibana 在后台使用上述查询来获取我尝试过的过滤器的结果。

【问题讨论】:

  • 为什么不在 url 中指定索引?使用“aggs”(聚合),因为构面已贬值。

标签: elasticsearch kibana facets


【解决方案1】:

这是一个带有前置过滤器(“query”:“*”)的查询示例,然后是一个 must&mustnot 查询。然后结果用于进行聚合:

curl -XGET 'http://localhost:9200/YOUR_INDEX_NAME/_search?size=10' -d '{
    "query" : {
        "filtered" : {
            "query" : {
                "query_string" : {
                    "query" : "*"
                }
            },
            "filter" : {
                 "bool" : {
                    "must" : [
                        { "term" : { "E_RECORDEDBY" : "malençon, g."} },
                        { "term" : { "T_SCIENTIFICNAME" : "peniophora incarnata"  } }
                    ],
                   "must_not" : [
                     {"term" : {    "L_CONTINENT" : "africa"    } },
                     {"term" : {    "L_CONTINENT" : "europe"    } }
                   ]
             }
            }
        }
    },   
    "aggs" : {
        "L_CONTINENT" : {
            "terms" : {
                "field" : "L_CONTINENT",
                "size" : 20
            }
        }
    },
    "sort" : "_score"
}'

【讨论】:

    猜你喜欢
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多