Ниже приведен пример ответа на поисковый запрос с 4 полученными результатами.Как фильтровать результаты ElasticSearch на основе значения поля?
{ "took": 13, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 4, "max_score": 0.41753215, "hits": [ { "_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea", "_type": "viz_dashlet", "_id": "/shared/Report_google_Shared", "_score": 0.41753215, "fields": { "lastModified": [ 1461738428007 ], "dir": [ "/shared" ], "filename": [ "Report_google_Shared" ] }, "highlight": { "filename": [ "Report_google_Shared" ] } }, { "_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea", "_type": "viz_dashlet", "_id": "/shared/Report_Gmail_Shared", "_score": 0.41753215, "fields": { "lastModified": [ 1461738618676 ], "dir": [ "/shared" ], "filename": [ "Report_Gmail_Shared" ] }, "highlight": { "filename": [ "Report_Gmail_Shared" ] } }, { "_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea", "_type": "viz_dashlet", "_id": "/private/hitesh/Report_Gmail_Private", "_score": 0.1883173, "fields": { "lastModified": [ 1461738629888 ], "dir": [ "/private/hitesh" ], "filename": [ "Report_Gmail_Private" ] }, "highlight": { "filename": [ "Report_Gmail_Private" ] } }, { "_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea", "_type": "viz_dashlet", "_id": "/private/dholaria/Report_google_Private", "_score": 0.1883173, "fields": { "lastModified": [ 1461738451720 ], "dir": [ "/private/dholaria" ], "filename": [ "Report_google_Private" ] }, "highlight": { "filename": [ "Report_google_Private" ] } } ] } }
Теперь я хочу отфильтровать приведенные выше результаты поиска по конкретному значению поля «dir» в соответствии с приведенными ниже критериями.
Включить результат поиска в ответ, если и только если:
- Если «реж» значение поля равно ни к одному из: «/ Shared» или «/ частных/Hitesh»
- Иначе, если " реж»значение поля начинается с любой из:„/ Shared /“или „/ частных/Hitesh /“
Как можно достичь вышеуказанной функциональности в ElasticSearch?
PS: Ниже приведен пример моего сопоставления.
{ "google_a804f89b-d32e-426a-a79a-ea83d65c98ea": { "mappings": { "viz_dashlet": { "properties": { "charts": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "columnLabels": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "columnNames": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "creator": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "dimensions": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "dir": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "expressions": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "filename": { "type": "string", "index_analyzer": "whitespace_index", "search_analyzer": "whitespace_search", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "lastModified": { "type": "date", "format": "date_hour_minute_second" }, "measures": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } }, "promptFilters": { "type": "string", "index_analyzer": "report_index_analyzer", "search_analyzer": "report_search_analyzer", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } } } } }
Что отображение 'dir' поля? 'GET/birst_a804f89b-d32e-426a-a79a-ea83d65c98ea/viz_dashlet/_mapping/field/dir' –
@AndreiStefan Добавлено отображение в самом вопросе. –