From ad2ca1497fe7a90c10a0210a4be2518abcc08dfd Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 2 Oct 2025 17:08:55 +0200 Subject: [PATCH 1/3] mdssvc: fix running test command manually BUG: https://bugzilla.samba.org/show_bug.cgi?id=15927 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit a8791c0cad4fb03606ea484c2da7ee69d9de5d48) --- source3/rpc_server/mdssvc/test_mdsparser_es.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source3/rpc_server/mdssvc/test_mdsparser_es.c b/source3/rpc_server/mdssvc/test_mdsparser_es.c index 02270a9b0662..8fc011220a44 100644 --- a/source3/rpc_server/mdssvc/test_mdsparser_es.c +++ b/source3/rpc_server/mdssvc/test_mdsparser_es.c @@ -200,16 +200,23 @@ static void test_mdsparser_es(void **state) TALLOC_CTX *frame = talloc_stackframe(); const char *path_scope = "/foo/bar"; char *es_query = NULL; + char *default_path = NULL; const char *path = NULL; json_t *mappings = NULL; json_error_t json_error; int i; bool ok; + default_path = talloc_asprintf( + frame, + "%s/mdssvc/elasticsearch_mappings.json", + get_dyn_SAMBA_DATADIR()); + assert_non_null(default_path); + path = lp_parm_const_string(GLOBAL_SECTION_SNUM, "elasticsearch", "mappings", - NULL); + default_path); assert_non_null(path); mappings = json_load_file(path, 0, &json_error); -- 2.50.0 From b0ce76e34b83e10bf0e5f96f0e1af9b51561bfb2 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 4 Sep 2025 17:41:44 +0200 Subject: [PATCH 2/3] mdssvc: fix filtering by share path prefix To correctly filter by share path, use a filter with a prefix match. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15927 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit 594eb4eb0eb4a6c87c5b136106afd05357b80e91) --- python/samba/tests/blackbox/mdsearch.py | 17 ++- python/samba/tests/dcerpc/mdssvc.py | 51 ++++++++- source3/rpc_server/mdssvc/es_parser.y | 8 +- source3/rpc_server/mdssvc/es_parser_test.c | 3 - source3/rpc_server/mdssvc/mdssvc_es.c | 33 ++++-- source3/rpc_server/mdssvc/test_mdsparser_es.c | 106 +++++++++--------- 6 files changed, 133 insertions(+), 85 deletions(-) diff --git a/python/samba/tests/blackbox/mdsearch.py b/python/samba/tests/blackbox/mdsearch.py index 8d67090e1821..7709ae6b032f 100644 --- a/python/samba/tests/blackbox/mdsearch.py +++ b/python/samba/tests/blackbox/mdsearch.py @@ -102,8 +102,21 @@ testfiles = [ json_in = r'''{ "from": 0, "size": 50, "_source": ["path.real"], "query": { - "query_string": { - "query": "(samba*) AND path.real.fulltext:\"%BASEPATH%\"" + "bool": { + "filter": [ + { + "prefix": { + "path.real": "%BASEPATH%/" + } + } + ], + "must": [ + { + "query_string": { + "query": "samba*" + } + } + ] } } }''' diff --git a/python/samba/tests/dcerpc/mdssvc.py b/python/samba/tests/dcerpc/mdssvc.py index cd256548b91d..a6e69f15474c 100644 --- a/python/samba/tests/dcerpc/mdssvc.py +++ b/python/samba/tests/dcerpc/mdssvc.py @@ -133,8 +133,21 @@ testfiles = [ exp_json_query = r'''{ "from": 0, "size": 50, "_source": ["path.real"], "query": { - "query_string": { - "query": "(samba*) AND path.real.fulltext:\"%BASEPATH%\"" + "bool": { + "filter": [ + { + "prefix": { + "path.real": "%BASEPATH%/" + } + } + ], + "must": [ + { + "query_string": { + "query": "samba*" + } + } + ] } } }''' @@ -165,8 +178,21 @@ testfiles = [ exp_json_query = r'''{ "from": 0, "size": 50, "_source": ["path.real"], "query": { - "query_string": { - "query": "(file.filename:x\\+x OR file.filename:x\\*x OR file.filename:x=x OR file.filename:x'x OR file.filename:x\\?x OR file.filename:x\\ x OR file.filename:x\\(x OR file.filename:x\\\"x OR file.filename:x\\\\x) AND path.real.fulltext:\"%BASEPATH%\"" + "bool": { + "filter": [ + { + "prefix": { + "path.real": "%BASEPATH%/" + } + } + ], + "must": [ + { + "query_string": { + "query": "file.filename:x\\+x OR file.filename:x\\*x OR file.filename:x=x OR file.filename:x'x OR file.filename:x\\?x OR file.filename:x\\ x OR file.filename:x\\(x OR file.filename:x\\\"x OR file.filename:x\\\\x" + } + } + ] } } }''' @@ -207,8 +233,21 @@ testfiles = [ exp_json_query = r'''{ "from": 0, "size": 50, "_source": ["path.real"], "query": { - "query_string": { - "query": "(*samba*) AND path.real.fulltext:\"%BASEPATH%\"" + "bool": { + "filter": [ + { + "prefix": { + "path.real": "%BASEPATH%/" + } + } + ], + "must": [ + { + "query_string": { + "query": "*samba*" + } + } + ] } } }''' diff --git a/source3/rpc_server/mdssvc/es_parser.y b/source3/rpc_server/mdssvc/es_parser.y index 7f3275d3d929..62ca63d90f20 100644 --- a/source3/rpc_server/mdssvc/es_parser.y +++ b/source3/rpc_server/mdssvc/es_parser.y @@ -85,7 +85,6 @@ int mdsyylwrap(void); bool map_spotlight_to_es_query(TALLOC_CTX *mem_ctx, json_t *mappings, - const char *path_scope, const char *query_string, char **_es_query); } @@ -640,7 +639,6 @@ int mdsyylwrap(void) **/ bool map_spotlight_to_es_query(TALLOC_CTX *mem_ctx, json_t *mappings, - const char *path_scope, const char *query_string, char **_es_query) { @@ -691,13 +689,11 @@ bool map_spotlight_to_es_query(TALLOC_CTX *mem_ctx, return false; } - es_query = talloc_asprintf(mem_ctx, - "(%s) AND path.real.fulltext:\\\"%s\\\"", - s.result, path_scope); - TALLOC_FREE(s.frame); + es_query = talloc_strdup(mem_ctx, s.result); if (es_query == NULL) { return false; } + TALLOC_FREE(s.frame); *_es_query = es_query; return true; diff --git a/source3/rpc_server/mdssvc/es_parser_test.c b/source3/rpc_server/mdssvc/es_parser_test.c index 7d88c67abffc..dfce8601911e 100644 --- a/source3/rpc_server/mdssvc/es_parser_test.c +++ b/source3/rpc_server/mdssvc/es_parser_test.c @@ -41,7 +41,6 @@ int main(int argc, char **argv) char *default_path = NULL; const char *path = NULL; const char *query_string = NULL; - const char *path_scope = NULL; char *es_query = NULL; bool ok; @@ -50,7 +49,6 @@ int main(int argc, char **argv) return 1; } query_string = argv[1]; - path_scope = "/foo/bar"; lp_load_global(get_dyn_CONFIGFILE()); @@ -86,7 +84,6 @@ int main(int argc, char **argv) ok = map_spotlight_to_es_query(mem_ctx, mappings, - path_scope, query_string, &es_query); printf("%s\n", ok ? es_query : "*mapping failed*"); diff --git a/source3/rpc_server/mdssvc/mdssvc_es.c b/source3/rpc_server/mdssvc/mdssvc_es.c index d51441092b42..83550bcdc235 100644 --- a/source3/rpc_server/mdssvc/mdssvc_es.c +++ b/source3/rpc_server/mdssvc/mdssvc_es.c @@ -36,17 +36,26 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_SRV -#define MDSSVC_ELASTIC_QUERY_TEMPLATE \ - "{" \ - " \"from\": %zu," \ - " \"size\": %zu," \ - " \"_source\": [%s]," \ - " \"query\": {" \ - " \"query_string\": {" \ - " \"query\": \"%s\"" \ - " }" \ - " }" \ - "}" +#define MDSSVC_ELASTIC_QUERY_TEMPLATE \ + "{\n" \ + " \"from\": %zu,\n" \ + " \"size\": %zu,\n" \ + " \"_source\": [%s],\n" \ + " \"query\": {\n" \ + " \"bool\": {\n" \ + " \"filter\": [ {\n" \ + " \"prefix\": {\n" \ + " \"path.real\": \"%s/\"\n" \ + " }\n" \ + " } ],\n" \ + " \"must\": [ {\n" \ + " \"query_string\": {\n" \ + " \"query\": \"%s\"\n" \ + " }\n" \ + " } ]\n" \ + " }\n" \ + " }\n" \ + "}\n" #define MDSSVC_ELASTIC_SOURCES \ "\"path.real\"" @@ -413,7 +422,6 @@ static bool mds_es_search(struct sl_query *slq) ok = map_spotlight_to_es_query( s, mds_es_ctx->mdssvc_es_ctx->mappings, - slq->path_scope, slq->query_string, &s->es_query); if (!ok) { @@ -621,6 +629,7 @@ static struct tevent_req *mds_es_search_send(TALLOC_CTX *mem_ctx, s->from, s->size, MDSSVC_ELASTIC_SOURCES, + s->slq->path_scope, s->es_query); if (tevent_req_nomem(elastic_query, req)) { return tevent_req_post(req, ev); diff --git a/source3/rpc_server/mdssvc/test_mdsparser_es.c b/source3/rpc_server/mdssvc/test_mdsparser_es.c index 8fc011220a44..a61f84ceaff9 100644 --- a/source3/rpc_server/mdssvc/test_mdsparser_es.c +++ b/source3/rpc_server/mdssvc/test_mdsparser_es.c @@ -28,136 +28,133 @@ #include "lib/param/param.h" #include "rpc_server/mdssvc/es_parser.tab.h" -#define PATH_QUERY_SUBEXPR \ - " AND path.real.fulltext:\\\"/foo/bar\\\"" - static struct { const char *mds; const char *es; } map[] = { { "*==\"samba\"", - "(samba)" PATH_QUERY_SUBEXPR + "samba" }, { "kMDItemTextContent==\"samba\"", - "(content:samba)" PATH_QUERY_SUBEXPR + "content:samba" }, { "_kMDItemGroupId==\"11\"", - "(file.content_type:(application\\\\/pdf))" PATH_QUERY_SUBEXPR + "file.content_type:(application\\\\/pdf)" }, { "kMDItemContentType==\"1\"", - "(file.content_type:(message\\\\/rfc822))" PATH_QUERY_SUBEXPR + "file.content_type:(message\\\\/rfc822)" }, { "kMDItemContentType==\"public.content\"", - "(file.content_type:(message\\\\/rfc822 application\\\\/pdf application\\\\/vnd.oasis.opendocument.presentation image\\\\/* text\\\\/*))" PATH_QUERY_SUBEXPR + "file.content_type:(message\\\\/rfc822 application\\\\/pdf application\\\\/vnd.oasis.opendocument.presentation image\\\\/* text\\\\/*)" }, { "kMDItemContentTypeTree==\"1\"", - "(file.content_type:(message\\\\/rfc822))" PATH_QUERY_SUBEXPR + "file.content_type:(message\\\\/rfc822)" }, { "kMDItemFSContentChangeDate==$time.iso(2018-10-01T10:00:00Z)", - "(file.last_modified:2018\\\\-10\\\\-01T10\\\\:00\\\\:00Z)" PATH_QUERY_SUBEXPR + "file.last_modified:2018\\\\-10\\\\-01T10\\\\:00\\\\:00Z" }, { "kMDItemFSContentChangeDate==\"1\"", - "(file.last_modified:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z)" PATH_QUERY_SUBEXPR + "file.last_modified:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z" }, { "kMDItemFSCreationDate==\"1\"", - "(file.created:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z)" PATH_QUERY_SUBEXPR + "file.created:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z" }, { "kMDItemFSName==\"samba*\"", - "(file.filename:samba*)" PATH_QUERY_SUBEXPR + "file.filename:samba*" }, { "kMDItemFSOwnerGroupID==\"0\"", - "(attributes.owner:0)" PATH_QUERY_SUBEXPR + "attributes.owner:0" }, { "kMDItemFSOwnerUserID==\"0\"", - "(attributes.group:0)" PATH_QUERY_SUBEXPR + "attributes.group:0" }, { "kMDItemFSSize==\"1\"", - "(file.filesize:1)" PATH_QUERY_SUBEXPR + "file.filesize:1" }, { "kMDItemPath==\"/foo/bar\"", - "(path.real:\\\\/foo\\\\/bar)" PATH_QUERY_SUBEXPR + "path.real:\\\\/foo\\\\/bar" }, { "kMDItemAttributeChangeDate==\"1\"", - "(file.last_modified:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z)" PATH_QUERY_SUBEXPR + "file.last_modified:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z" }, { "kMDItemAuthors==\"Chouka\"", - "(meta.author:Chouka)" PATH_QUERY_SUBEXPR + "meta.author:Chouka" }, { "kMDItemContentCreationDate==\"1\"", - "(file.created:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z)" PATH_QUERY_SUBEXPR + "file.created:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z" }, { "kMDItemContentModificationDate==\"1\"", - "(file.last_modified:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z)" PATH_QUERY_SUBEXPR + "file.last_modified:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z" }, { "kMDItemCreator==\"Chouka\"", - "(meta.raw.creator:Chouka)" PATH_QUERY_SUBEXPR + "meta.raw.creator:Chouka" }, { "kMDItemDescription==\"Dog\"", - "(meta.raw.description:Dog)" PATH_QUERY_SUBEXPR + "meta.raw.description:Dog" }, { "kMDItemDisplayName==\"Samba\"", - "(file.filename:Samba)" PATH_QUERY_SUBEXPR + "file.filename:Samba" }, { "kMDItemDurationSeconds==\"1\"", - "(meta.raw.xmpDM\\\\:duration:1)" PATH_QUERY_SUBEXPR + "meta.raw.xmpDM\\\\:duration:1" }, { "kMDItemNumberOfPages==\"1\"", - "(meta.raw.xmpTPg\\\\:NPages:1)" PATH_QUERY_SUBEXPR + "meta.raw.xmpTPg\\\\:NPages:1" }, { "kMDItemTitle==\"Samba\"", - "(meta.title:Samba)" PATH_QUERY_SUBEXPR + "meta.title:Samba" }, { "kMDItemAlbum==\"Red Roses for Me\"", - "(meta.raw.xmpDM\\\\:album:Red\\\\ Roses\\\\ for\\\\ Me)" PATH_QUERY_SUBEXPR + "meta.raw.xmpDM\\\\:album:Red\\\\ Roses\\\\ for\\\\ Me" }, { "kMDItemBitsPerSample==\"1\"", - "(meta.raw.tiff\\\\:BitsPerSample:1)" PATH_QUERY_SUBEXPR + "meta.raw.tiff\\\\:BitsPerSample:1" }, { "kMDItemPixelHeight==\"1\"", - "(meta.raw.Image\\\\ Height:1)" PATH_QUERY_SUBEXPR + "meta.raw.Image\\\\ Height:1" }, { "kMDItemPixelWidth==\"1\"", - "(meta.raw.Image\\\\ Width:1)" PATH_QUERY_SUBEXPR + "meta.raw.Image\\\\ Width:1" }, { "kMDItemResolutionHeightDPI==\"72\"", - "(meta.raw.Y\\\\ Resolution:72)" PATH_QUERY_SUBEXPR + "meta.raw.Y\\\\ Resolution:72" }, { "kMDItemResolutionWidthDPI==\"72\"", - "(meta.raw.X\\\\ Resolution:72)" PATH_QUERY_SUBEXPR + "meta.raw.X\\\\ Resolution:72" },{ "*!=\"samba\"", - "((NOT samba))" PATH_QUERY_SUBEXPR + "(NOT samba)" }, { "kMDItemFSSize!=\"1\"", - "((NOT file.filesize:1))" PATH_QUERY_SUBEXPR + "(NOT file.filesize:1)" }, { "kMDItemFSSize>\"1\"", - "(file.filesize:{1 TO *})" PATH_QUERY_SUBEXPR + "file.filesize:{1 TO *}" }, { "kMDItemFSSize<\"1\"", - "(file.filesize:{* TO 1})" PATH_QUERY_SUBEXPR + "file.filesize:{* TO 1}" }, { "kMDItemFSCreationDate!=\"1\"", - "((NOT file.created:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z))" PATH_QUERY_SUBEXPR + "(NOT file.created:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z)" }, { "kMDItemFSCreationDate>\"1\"", - "(file.created:{2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z TO *})" PATH_QUERY_SUBEXPR + "file.created:{2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z TO *}" }, { "kMDItemFSCreationDate<\"1\"", - "(file.created:{* TO 2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z})" PATH_QUERY_SUBEXPR + "file.created:{* TO 2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z}" }, { "kMDItemFSName==\"Samba\"||kMDItemTextContent==\"Samba\"", - "(file.filename:Samba OR content:Samba)" PATH_QUERY_SUBEXPR + "file.filename:Samba OR content:Samba" }, { "kMDItemFSName==\"Samba\"&&kMDItemTextContent==\"Samba\"", - "((file.filename:Samba) AND (content:Samba))" PATH_QUERY_SUBEXPR + "(file.filename:Samba) AND (content:Samba)" }, { "InRange(kMDItemFSCreationDate,1,2)", - "(file.created:[2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z TO 2001\\\\-01\\\\-01T00\\\\:00\\\\:02Z])" PATH_QUERY_SUBEXPR + "file.created:[2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z TO 2001\\\\-01\\\\-01T00\\\\:00\\\\:02Z]" }, { "InRange(kMDItemFSSize,1,2)", - "(file.filesize:[1 TO 2])" PATH_QUERY_SUBEXPR + "file.filesize:[1 TO 2]" } }; @@ -167,38 +164,37 @@ static struct { } map_ignore_failures[] = { { "*==\"Samba\"||foo==\"bar\"", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "*==\"Samba\"&&foo==\"bar\"", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "*==\"Samba\"||kMDItemContentType==\"666\"", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "*==\"Samba\"&&kMDItemContentType==\"666\"", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "*==\"Samba\"||foo==\"bar\"||kMDItemContentType==\"666\"", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "*==\"Samba\"&&foo==\"bar\"&&kMDItemContentType==\"666\"", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "foo==\"bar\"||kMDItemContentType==\"666\"||*==\"Samba\"||x!=\"6\"", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "*==\"Samba\"||InRange(foo,1,2)", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" }, { "*==\"Samba\"||foo==$time.iso(2018-10-01T10:00:00Z)", - "(Samba)" PATH_QUERY_SUBEXPR + "Samba" } }; static void test_mdsparser_es(void **state) { TALLOC_CTX *frame = talloc_stackframe(); - const char *path_scope = "/foo/bar"; char *es_query = NULL; char *default_path = NULL; const char *path = NULL; @@ -226,7 +222,6 @@ static void test_mdsparser_es(void **state) DBG_DEBUG("Mapping: %s\n", map[i].mds); ok = map_spotlight_to_es_query(frame, mappings, - path_scope, map[i].mds, &es_query); assert_true(ok); @@ -245,7 +240,6 @@ static void test_mdsparser_es(void **state) DBG_DEBUG("Mapping: %s\n", map_ignore_failures[i].mds); ok = map_spotlight_to_es_query(frame, mappings, - path_scope, map_ignore_failures[i].mds, &es_query); assert_true(ok); -- 2.50.0 From cc9de5803c60568c56d4e5d73193fedffa6921a6 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 1 Sep 2025 14:55:04 +0200 Subject: [PATCH 3/3] mdssvc: implement elasticsearch:default_fields BUG: https://bugzilla.samba.org/show_bug.cgi?id=15927 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit 2b5cbb955ab2cf278272aa8457a672aa27ff1020) --- .../misc/elasticsearchdefaultfields.xml | 19 ++++++++++++ python/samba/tests/blackbox/mdsearch.py | 3 +- python/samba/tests/dcerpc/mdssvc.py | 9 ++++-- source3/rpc_server/mdssvc/mdssvc_es.c | 29 ++++++++++++++----- source3/rpc_server/mdssvc/mdssvc_es.h | 1 + 5 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 docs-xml/smbdotconf/misc/elasticsearchdefaultfields.xml diff --git a/docs-xml/smbdotconf/misc/elasticsearchdefaultfields.xml b/docs-xml/smbdotconf/misc/elasticsearchdefaultfields.xml new file mode 100644 index 000000000000..9230e9280b74 --- /dev/null +++ b/docs-xml/smbdotconf/misc/elasticsearchdefaultfields.xml @@ -0,0 +1,19 @@ + + + + Default attributes in Elasticsearch to query when receiving a Spotlight + query that searches in the special attribute "*". This is the default used + by macOS clients when searching from the Finder. + + + This option expects a list of Elasticsearch attributes separated by + comma where each attributes must be enclosed in double quotes. + + + + "file.filename", "content" + "foo", "bar" + diff --git a/python/samba/tests/blackbox/mdsearch.py b/python/samba/tests/blackbox/mdsearch.py index 7709ae6b032f..a2e6eb09029d 100644 --- a/python/samba/tests/blackbox/mdsearch.py +++ b/python/samba/tests/blackbox/mdsearch.py @@ -113,7 +113,8 @@ testfiles = [ "must": [ { "query_string": { - "query": "samba*" + "query": "samba*", + "fields": ["file.filename", "content"] } } ] diff --git a/python/samba/tests/dcerpc/mdssvc.py b/python/samba/tests/dcerpc/mdssvc.py index a6e69f15474c..40005ff18244 100644 --- a/python/samba/tests/dcerpc/mdssvc.py +++ b/python/samba/tests/dcerpc/mdssvc.py @@ -144,7 +144,8 @@ testfiles = [ "must": [ { "query_string": { - "query": "samba*" + "query": "samba*", + "fields": ["file.filename", "content"] } } ] @@ -189,7 +190,8 @@ testfiles = [ "must": [ { "query_string": { - "query": "file.filename:x\\+x OR file.filename:x\\*x OR file.filename:x=x OR file.filename:x'x OR file.filename:x\\?x OR file.filename:x\\ x OR file.filename:x\\(x OR file.filename:x\\\"x OR file.filename:x\\\\x" + "query": "file.filename:x\\+x OR file.filename:x\\*x OR file.filename:x=x OR file.filename:x'x OR file.filename:x\\?x OR file.filename:x\\ x OR file.filename:x\\(x OR file.filename:x\\\"x OR file.filename:x\\\\x", + "fields": ["file.filename", "content"] } } ] @@ -244,7 +246,8 @@ testfiles = [ "must": [ { "query_string": { - "query": "*samba*" + "query": "*samba*", + "fields": ["file.filename", "content"] } } ] diff --git a/source3/rpc_server/mdssvc/mdssvc_es.c b/source3/rpc_server/mdssvc/mdssvc_es.c index 83550bcdc235..eb19d5fdc4a1 100644 --- a/source3/rpc_server/mdssvc/mdssvc_es.c +++ b/source3/rpc_server/mdssvc/mdssvc_es.c @@ -50,7 +50,8 @@ " } ],\n" \ " \"must\": [ {\n" \ " \"query_string\": {\n" \ - " \"query\": \"%s\"\n" \ + " \"query\": \"%s\",\n" \ + " \"fields\": [%s]\n" \ " }\n" \ " } ]\n" \ " }\n" \ @@ -66,6 +67,7 @@ static bool mdssvc_es_init(struct mdssvc_ctx *mdssvc_ctx) json_error_t json_error; char *default_path = NULL; const char *path = NULL; + const char *default_fields = "\"file.filename\", \"content\""; mdssvc_es_ctx = talloc_zero(mdssvc_ctx, struct mdssvc_es_ctx); if (mdssvc_es_ctx == NULL) { @@ -106,6 +108,15 @@ static bool mdssvc_es_init(struct mdssvc_ctx *mdssvc_ctx) } TALLOC_FREE(default_path); + mdssvc_es_ctx->default_fields = lp_parm_const_string(GLOBAL_SECTION_SNUM, + "elasticsearch", + "default_fields", + default_fields); + if (mdssvc_es_ctx->default_fields == NULL) { + TALLOC_FREE(mdssvc_es_ctx); + return false; + } + mdssvc_ctx->backend_private = mdssvc_es_ctx; return true; } @@ -624,13 +635,15 @@ static struct tevent_req *mds_es_search_send(TALLOC_CTX *mem_ctx, return tevent_req_post(req, ev); } - elastic_query = talloc_asprintf(state, - MDSSVC_ELASTIC_QUERY_TEMPLATE, - s->from, - s->size, - MDSSVC_ELASTIC_SOURCES, - s->slq->path_scope, - s->es_query); + elastic_query = talloc_asprintf( + state, + MDSSVC_ELASTIC_QUERY_TEMPLATE, + s->from, + s->size, + MDSSVC_ELASTIC_SOURCES, + s->slq->path_scope, + s->es_query, + s->mds_es_ctx->mdssvc_es_ctx->default_fields); if (tevent_req_nomem(elastic_query, req)) { return tevent_req_post(req, ev); } diff --git a/source3/rpc_server/mdssvc/mdssvc_es.h b/source3/rpc_server/mdssvc/mdssvc_es.h index 19797fa24f34..154b0b4667a6 100644 --- a/source3/rpc_server/mdssvc/mdssvc_es.h +++ b/source3/rpc_server/mdssvc/mdssvc_es.h @@ -30,6 +30,7 @@ struct mdssvc_es_ctx { struct mdssvc_ctx *mdssvc_ctx; struct cli_credentials *creds; json_t *mappings; + const char *default_fields; }; /* -- 2.50.0