2016-10-14 5 views
0

Я хочу получить диапазон дат с определенным идентификатором, но мой результат включает в себя другие идентификаторы. Мне нужна помощь в проверке запроса.Фильтр с elasticsearch

Это то, что я пытаюсь сделать

Fectch все документы, где UniqueID == 1 и начало диапазон от 2016-10-11T12: 00: 30.000Z к «2016-10-12T12 : 00: 30.000Z "

Мой запрос и результаты показаны ниже.

Запрос

GET _search 

{ 
"query": { 
    "constant_score": { 
     "filter": { 
      "bool": { 
       "must": [ 
        { 
         "term": { 
         "uniqueid": 1 
         } 
        } 
       ], 
       "should": [ 
        { 
        "range": { 
       "start": { 
       "from": "2016-10-11T12:00:30.000Z", 
       "to": "2016-10-12T12:00:30.000Z" 
       } 
      } 
        } 
       ] 
      } 
     } 
    } 
    } 
} 

Результат

{ 
    "took": 15, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 6, 
    "max_score": 1, 
    "hits": [ 
    { 
     "_index": "cdr", 
     "_type": "face", 
     "_id": "AVfDCsC-vh94Tg1hrkix", 
     "_score": 1, 
     "_source": { 
      "start": "2016-10-12T12:00:30.000Z", 
      "answer": "2016-10-12T12:00:25.000Z", 
      "end": "2016-10-12T12:00:35.000Z", 
      "duration": 50, 
      "billsec": 55, 
      "uniqueid": 1, 
      "is_successful": true, 
      "is_clicked": true 
     } 
    }, 
    { 
     "_index": "cdr", 
     "_type": "face", 
     "_id": "AVfDCucPvh94Tg1hrkiy", 
     "_score": 1, 
     "_source": { 
      "start": "2016-10-12T12:00:30.000Z", 
      "answer": "2016-10-12T12:00:25.000Z", 
      "end": "2016-10-12T12:00:35.000Z", 
      "duration": 50, 
      "billsec": 55, 
      "uniqueid": 2, 
      "is_successful": true, 
      "is_clicked": true 
     } 
    }, 
    { 
     "_index": "cdr", 
     "_type": "face", 
     "_id": "AVfDC1G2vh94Tg1hrkiz", 
     "_score": 1, 
     "_source": { 
      "start": "2016-10-13T12:00:30.000Z", 
      "answer": "2016-10-13T12:00:25.000Z", 
      "end": "2016-10-13T12:00:35.000Z", 
      "duration": 50, 
      "billsec": 55, 
      "uniqueid": 2, 
      "is_successful": true, 
      "is_clicked": true 
     } 
    }, 
    { 
     "_index": "cdr", 
     "_type": "face", 
     "_id": "AVfDC2IGvh94Tg1hrki0", 
     "_score": 1, 
     "_source": { 
      "start": "2016-10-13T12:00:30.000Z", 
      "answer": "2016-10-13T12:00:25.000Z", 
      "end": "2016-10-13T12:00:35.000Z", 
      "duration": 50, 
      "billsec": 55, 
      "uniqueid": 1, 
      "is_successful": true, 
      "is_clicked": true 
     } 
    }, 
    { 
     "_index": "cdr", 
     "_type": "face", 
     "_id": "AVfDCCOOvh94Tg1hrkiv", 
     "_score": 1, 
     "_source": { 
      "start": "2016-10-10T12:00:15.000Z", 
      "answer": "2016-10-10T12:00:25.000Z", 
      "end": "2016-10-10T12:00:35.000Z", 
      "duration": 25, 
      "billsec": 25, 
      "uniqueid": 1, 
      "is_successful": true, 
      "is_clicked": true 
     } 
    }, 
    { 
     "_index": "cdr", 
     "_type": "face", 
     "_id": "AVfDCR2Uvh94Tg1hrkiw", 
     "_score": 1, 
     "_source": { 
      "start": "2016-10-11T12:00:15.000Z", 
      "answer": "2016-10-11T12:00:25.000Z", 
      "end": "2016-10-11T12:00:35.000Z", 
      "duration": 25, 
      "billsec": 25, 
      "uniqueid": 1, 
      "is_successful": true, 
      "is_clicked": true 
      } 
     } 
     ] 
    } 
} 
+0

переместить запрос 'range' в массив' must'. а также использовать POST вместо GET при отправке полезной нагрузки. – Val

+0

@Val Я пробовал это, все еще не работает – SimpiMind

+0

Даже при использовании POST вместо GET? – Val

ответ

1

Вы должны удалить пустую строку ниже URL пути

GET _search 
         <--- remove this line 
{ 
"query": { 

Как это:

GET _search 
{ 
    "query": { 
1

Как сказал @Val, перемещение диапазона в must должно работать.

{ 
"query": { 
    "constant_score": { 
     "filter": { 
      "bool": { 
       "must": [ 
        { 
        "term": { 
         "uniqueid": 1 
        } 
        }, 
        { 
        "range": { 
         "start": { 
          "from": "2016-10-11T12:00:30.000Z", 
          "to": "2016-10-12T12:00:30.000Z" 
         } 
        } 
        } 
       ] 
      } 
     } 
    } 
    } 
} 
+0

Проблема была больше связана с пустой строкой, которая посылала бы пустой запрос (т. Е. 'Match_all'). Его первоначальный запрос был более или менее точным в отношении ограничения на 'uniqueid' – Val

Смежные вопросы