【问题标题】:Riak SOLR over HTTP and date ranges?Riak SOLR over HTTP 和日期范围?
【发布时间】:2014-06-07 02:41:02
【问题描述】:

在使用 SOLR api over HTTP 进行搜索时,谁能告诉我 Riak 对日期格式的期望?我有一些已编入索引的数据。通配符搜索确认:

{
    "responseHeader": {
        "status": 0,
        "QTime": 13,
        "params": {
            "q": "*",
            "q.op": "or",
            "filter": "",
            "wt": "json"
        }
    },
    "response": {
        "numFound": 2,
        "start": 0,
        "maxScore": "0.00000e+0",
        "docs": [
            {
                "id": "09d1bf74-9cdc-4001-8797-fc5a4b9170b0",
                "index": "TestIndex",
                "fields": {
                    "Timestamp_dt": "2014-06-06T02:10:35.367Z"
                },
                "props": {}
            },
            {
                "id": "09d1bf74-9cdc-4001-8797-fc5a4b9170b0",
                "index": "TestIndex",
                "fields": {
                    "Timestamp_dt": "2014-06-08T02:10:35.367Z"
                },
                "props": {}
            }
        ]
    }
}

我还确认我的架构选择了 _dt 作为日期时间:

%% Field names ending in "_dt" are indexed as dates
        {dynamic_field, [
            {name, "*_dt"},
            {type, date},
            {analyzer_factory, {erlang, text_analyzers, noop_analyzer_factory}}
        ]},

我尝试了很多变体,包括这些:

/solr/TestIndex/select?wt=json&q=Timestamp_dt:[20140508000000%20TO%2020140608000000]
/solr/TestIndex/select?wt=json&q=Timestamp_dt:[20140508T000000Z TO 20140607T000000Z]
/solr/TestIndex/select?wt=json&q=Timestamp_dt:%5B2014-05-08T00%3A00%3A00.000Z%20TO%202014-06-07T00%3A00%3A00.000Z%5D

我很难过,而且日期范围的文档有些缺乏。有没有人让这个工作?我是否坚持转换为纪元日期时间?

【问题讨论】:

    标签: solr riak riak-search riak-cs


    【解决方案1】:

    日期字段使用 noop 分析器,因此索引文本将与您存储的文本完全相同。但是,冒号是查询中的活动字符,因此您需要在值中对其进行转义:

    % curl localhost:8098/buckets/testbucket/keys/1 -XPUT -H "content-type: application/json" \
      -d '{"item":"1","stamp_dt":"2014-06-06T02:10:35.367Z"}'
    % curl localhost:8098/buckets/testbucket/keys/2 -XPUT -H "content-type: application/json" \
      -d '{"item":"2","stamp_dt":"2014-06-07T02:10:35.367Z"}'
    % curl localhost:8098/buckets/testbucket/keys/3 -XPUT -H "content-type: application/json" \
      -d '{"item":"3","stamp_dt":"2014-06-07T06:10:35.367Z"}'
    
    % curl -g 'localhost:8098/solr/testbucket/select?q=stamp_dt:2014-06-06T02\:10\:35.367Z'
    <?xml version="1.0" encoding="UTF-8"?>
    <response>
      <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">1</int>
        <lst name="params">
          <str name="indent">on</str>
          <str name="start">0</str>
          <str name="q">stamp_dt:2014-06-06T02\:10\:35.367Z</str>
          <str name="q.op">or</str>
          <str name="filter"></str>
          <str name="df">value</str>
          <str name="wt">standard</str>
          <str name="version">1.1</str>
          <str name="rows">1</str>
        </lst>
      </lst>
      <result name="response" numFound="1" start="0" maxScore="0.353553">
        <doc>
          <str name="id">1
          </str>
          <str name="item">1
          </str>
          <date name="stamp_dt">2014-06-06T02:10:35.367Z
          </date>
        </doc>
      </result>
    </response>
    

    您选择的日期格式也很适合范围查询(不确定为什么必须将空格显式 url 编码为 %20):

    % curl -g 'localhost:8098/solr/testbucket/select?q=stamp_dt:[2014-06-06%20TO%202014-06-07T23\:59]'
    <?xml version="1.0" encoding="UTF-8"?>
    <response>
      <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">4</int>
        <lst name="params">
          <str name="indent">on</str>
          <str name="start">0</str>
          <str name="q">stamp_dt:[2014-06-06 TO 2014-06-07T23\:59]</str>
          <str name="q.op">or</str>
          <str name="filter"></str>
          <str name="df">value</str>
          <str name="wt">standard</str>
          <str name="version">1.1</str>
          <str name="rows">3</str>
        </lst>
      </lst>
      <result name="response" numFound="3" start="0" maxScore="0.00000e+0">
        <doc>
          <str name="id">1
          </str>
          <str name="item">1
          </str>
          <date name="stamp_dt">2014-06-06T02:10:35.367Z
          </date>
        </doc>
        <doc>
          <str name="id">2
          </str>
          <str name="item">2
          </str>
          <date name="stamp_dt">2014-06-07T02:10:35.367Z
          </date>
        </doc>
        <doc>
          <str name="id">3
          </str>
          <str name="item">3
          </str>
          <date name="stamp_dt">2014-06-07T06:10:35.367Z
          </date>
        </doc>
      </result>
    </response>
    

    【讨论】:

      猜你喜欢
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      • 2017-05-05
      相关资源
      最近更新 更多