1

我对 Elasticsearch Term Facet 有疑问

我把数据如下:

curl -X DELETE "http://localhost:9200/articles'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "One",   "tags" : "foo","datetime":"2005-12-23 23:10:52"}'


curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Two",   "tags" : "bar","datetime":"2005-12-23 23:10:53"}'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Three", "tags" : "baz","datetime":"2005-12-23 23:10:54"}'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "four", "tags" : "baz","datetime":"2005-12-23 23:10:55"}'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "five", "tags" : "foo","datetime":"2005-12-23 23:10:56"}'

因此,每当我查询术语方面时,它都会给出正确的结果,以下是我的 Elasticsearch 查询:

curl  'http://localhost:9200/articles/article/_search?pretty=true' -d '{

   "query": {
       "match_all": {}
   },
    "facets" : { "myfacet" : { "terms" : {"field" : "tags"}}
    }
}'

但是,当我向 Facet 添加过滤器时,它不会显示任何方面计数以下是查询:

curl  'http://localhost:9200/articles/article/_search?pretty=true' -d '{

   "query": {
       "match_all": {}
   },
   "facets" : {
        "myfacet" : { "terms" : {"field" : "tags"},
             "filter" : { "range" :{
 "datetime" : {"from" : "2005-12-23   3:10:52","to" : "2005-12-23 23:10:56" }

        }
            }
    }
    }
}'

我得到如下结果

facets" : {
    "myfacet" : {
      "_type" : "filter",
      "count" : 0
    }
  }

所以,任何人都知道为什么它给出这样的计数。

4

1 回答 1

1

日期格式无效,看一下elasticsearch支持的日期时间格式(太长了,别看了,jodatime支持的任何日期都是elasticsearch支持的)。

http://www.elasticsearch.org/guide/reference/mapping/date-format.html

话虽如此,您只需要修改插入语句中的日期并将它们置于有效的日期格式中,例如2005-12-23T23:10:55Z. 然后只需将您的查询更改为该时间格式的适当时间范围,这应该会给您结果。

编写这些查询时也要小心,因为我注意到您在 from 子句中使用的日期无效。

以下是修改后的 curl 脚本:

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "One",   "tags" : "foo","datetime":"2005-12-23T23:10:52Z"}'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Two",   "tags" : "bar","datetime":"2005-12-23T23:10:53Z"}'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Three", "tags" : "baz","datetime":"2005-12-23T23:10:54Z"}'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "four", "tags" : "baz","datetime":"2005-12-23T23:10:55Z"}'

curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "five", "tags" : "foo","datetime":"2005-12-23T23:10:56Z"}'

和修改后的搜索:

 curl  'http://localhost:9200/articles/article/_search?pretty=true' -d '{

   "query": {
      "match_all": {}
    },
    "facets" : {
     "myfacet" : { 
         "terms" : {"field" : "tags"},
         "filter" : { "range" :{
                         "datetime" : {
                             "from" : "2005-12-23T23:10:52Z",
                              "to" : "2005-12-23T23:10:54Z" 
                          }   
                       }
                    }
                  }
             }
}'

希望这会有所帮助,马特

于 2013-01-24T06:08:08.967 回答