diff --git a/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.test.ts b/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.test.ts index 570d2fc9192c0b..5a219304cea18b 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.test.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.test.ts @@ -136,6 +136,29 @@ describe('Index Fields', () => { readFromDocValues: false, esTypes: [], }, + { + aggregatable: true, + category: 'agent', + esTypes: [], + indexes: ['auditbeat'], + name: 'agent.user.name', + readFromDocValues: false, + searchable: true, + type: 'string', + }, + { + aggregatable: true, + category: 'client', + description: + 'Unique number allocated to the autonomous system. The autonomous system number (ASN) uniquely identifies each network on the Internet.', + esTypes: [], + example: 15169, + indexes: ['auditbeat'], + name: 'client.as.number.text', + readFromDocValues: false, + searchable: true, + type: 'string', + }, ]) ); }); @@ -149,6 +172,7 @@ describe('Index Fields', () => { ); expect(fields).toEqual([ { + category: 'base', description: 'Each document has an _id that uniquely identifies it', example: 'Y-6TfmcB0WOhS6qyMv3s', name: '_id', @@ -156,11 +180,11 @@ describe('Index Fields', () => { searchable: true, aggregatable: false, readFromDocValues: false, - category: 'base', - indexes: ['auditbeat'], esTypes: [], + indexes: ['auditbeat'], }, { + category: 'base', description: 'An index is like a ‘database’ in a relational database. It has a mapping which defines multiple types. An index is a logical namespace which maps to one or more primary shards and can have zero or more replica shards.', example: 'auditbeat-8.0.0-2019.02.19-000001', @@ -169,11 +193,11 @@ describe('Index Fields', () => { searchable: true, aggregatable: true, readFromDocValues: false, - category: 'base', - indexes: ['auditbeat'], esTypes: [], + indexes: ['auditbeat'], }, { + category: 'base', description: 'Date/time when the event originated. This is the date/time extracted from the event, typically representing when the event was generated by the source. If the event source has no original timestamp, this value is typically populated by the first time the event was received by the pipeline. Required field for all events.', example: '2016-05-23T08:05:34.853Z', @@ -181,12 +205,12 @@ describe('Index Fields', () => { type: 'date', searchable: true, aggregatable: true, - category: 'base', - indexes: ['auditbeat'], readFromDocValues: true, esTypes: [], + indexes: ['auditbeat'], }, { + category: 'agent', description: 'Ephemeral identifier of this agent (if one exists). This id normally changes across restarts, but `agent.id` does not.', example: '8a4f500f', @@ -194,12 +218,12 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'agent', - indexes: ['auditbeat'], readFromDocValues: false, esTypes: [], + indexes: ['auditbeat'], }, { + category: 'agent', description: 'Custom name of the agent. This is a name that can be given to an agent. This can be helpful if for example two Filebeat instances are running on the same host but a human readable separation is needed on which Filebeat instance data is coming from. If no name is given, the name is often left empty.', example: 'foo', @@ -207,12 +231,12 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'agent', - indexes: ['auditbeat'], readFromDocValues: false, esTypes: [], + indexes: ['auditbeat'], }, { + category: 'agent', description: 'Type of the agent. The agent type stays always the same and should be given by the agent used. In case of Filebeat the agent would always be Filebeat also if two Filebeat instances are run on the same machine.', example: 'filebeat', @@ -220,36 +244,59 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'agent', - indexes: ['auditbeat'], readFromDocValues: false, esTypes: [], + indexes: ['auditbeat'], }, { + category: 'agent', description: 'Version of the agent.', example: '6.0.0-rc2', name: 'agent.version', type: 'string', searchable: true, aggregatable: true, + readFromDocValues: false, + esTypes: [], + indexes: ['auditbeat'], + }, + { category: 'agent', + name: 'agent.user.name', + searchable: true, + type: 'string', + aggregatable: true, + readFromDocValues: false, + esTypes: [], indexes: ['auditbeat'], + }, + { + category: 'client', + description: + 'Unique number allocated to the autonomous system. The autonomous system number (ASN) uniquely identifies each network on the Internet.', + example: 15169, + name: 'client.as.number.text', + type: 'string', + searchable: true, + aggregatable: true, readFromDocValues: false, esTypes: [], + indexes: ['auditbeat'], }, { + category: 'base', description: 'Each document has an _id that uniquely identifies it', example: 'Y-6TfmcB0WOhS6qyMv3s', name: '_id', type: 'string', searchable: true, aggregatable: false, - category: 'base', - indexes: ['filebeat'], readFromDocValues: false, esTypes: [], + indexes: ['filebeat'], }, { + category: 'base', description: 'An index is like a ‘database’ in a relational database. It has a mapping which defines multiple types. An index is a logical namespace which maps to one or more primary shards and can have zero or more replica shards.', example: 'auditbeat-8.0.0-2019.02.19-000001', @@ -257,12 +304,12 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'base', - indexes: ['filebeat'], readFromDocValues: false, esTypes: [], + indexes: ['filebeat'], }, { + category: 'base', description: 'Date/time when the event originated. This is the date/time extracted from the event, typically representing when the event was generated by the source. If the event source has no original timestamp, this value is typically populated by the first time the event was received by the pipeline. Required field for all events.', example: '2016-05-23T08:05:34.853Z', @@ -270,24 +317,24 @@ describe('Index Fields', () => { type: 'date', searchable: true, aggregatable: true, - category: 'base', - indexes: ['filebeat'], readFromDocValues: true, esTypes: [], + indexes: ['filebeat'], }, { + category: 'agent', description: 'Deprecated - use agent.name or agent.id to identify an agent. Hostname of the agent. ', name: 'agent.hostname', - searchable: true, type: 'string', + searchable: true, aggregatable: true, - category: 'agent', - indexes: ['filebeat'], readFromDocValues: false, esTypes: [], + indexes: ['filebeat'], }, { + category: 'agent', description: 'Custom name of the agent. This is a name that can be given to an agent. This can be helpful if for example two Filebeat instances are running on the same host but a human readable separation is needed on which Filebeat instance data is coming from. If no name is given, the name is often left empty.', example: 'foo', @@ -295,36 +342,36 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'agent', - indexes: ['filebeat'], readFromDocValues: false, esTypes: [], + indexes: ['filebeat'], }, { + category: 'agent', description: 'Version of the agent.', example: '6.0.0-rc2', name: 'agent.version', type: 'string', searchable: true, aggregatable: true, - category: 'agent', - indexes: ['filebeat'], readFromDocValues: false, esTypes: [], + indexes: ['filebeat'], }, { + category: 'base', description: 'Each document has an _id that uniquely identifies it', example: 'Y-6TfmcB0WOhS6qyMv3s', name: '_id', type: 'string', searchable: true, aggregatable: false, - category: 'base', - indexes: ['packetbeat'], readFromDocValues: false, esTypes: [], + indexes: ['packetbeat'], }, { + category: 'base', description: 'An index is like a ‘database’ in a relational database. It has a mapping which defines multiple types. An index is a logical namespace which maps to one or more primary shards and can have zero or more replica shards.', example: 'auditbeat-8.0.0-2019.02.19-000001', @@ -332,12 +379,12 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'base', - indexes: ['packetbeat'], readFromDocValues: false, esTypes: [], + indexes: ['packetbeat'], }, { + category: 'base', description: 'Date/time when the event originated. This is the date/time extracted from the event, typically representing when the event was generated by the source. If the event source has no original timestamp, this value is typically populated by the first time the event was received by the pipeline. Required field for all events.', example: '2016-05-23T08:05:34.853Z', @@ -345,12 +392,12 @@ describe('Index Fields', () => { type: 'date', searchable: true, aggregatable: true, - category: 'base', - indexes: ['packetbeat'], readFromDocValues: true, esTypes: [], + indexes: ['packetbeat'], }, { + category: 'agent', description: 'Unique identifier of this agent (if one exists). Example: For Beats this would be beat.id.', example: '8a4f500d', @@ -358,12 +405,12 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'agent', - indexes: ['packetbeat'], readFromDocValues: false, esTypes: [], + indexes: ['packetbeat'], }, { + category: 'agent', description: 'Type of the agent. The agent type stays always the same and should be given by the agent used. In case of Filebeat the agent would always be Filebeat also if two Filebeat instances are run on the same machine.', example: 'filebeat', @@ -371,10 +418,9 @@ describe('Index Fields', () => { type: 'string', searchable: true, aggregatable: true, - category: 'agent', - indexes: ['packetbeat'], readFromDocValues: false, esTypes: [], + indexes: ['packetbeat'], }, ]); }); diff --git a/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.ts b/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.ts index 403a9425b221fa..71b641237d6b01 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/index_fields/index.ts @@ -121,8 +121,17 @@ export const createFieldItem = ( indexesAliasIdx: number ): IndexField => { const alias = indexesAlias[indexesAliasIdx]; + const splitIndexName = index.name.split('.'); + const indexName = + splitIndexName[splitIndexName.length - 1] === 'text' + ? splitIndexName.slice(0, splitIndexName.length - 1).join('.') + : index.name; + const beatIndex = fieldsBeat[indexName] ?? {}; + if (isEmpty(beatIndex.category)) { + beatIndex.category = splitIndexName[0]; + } return { - ...(fieldsBeat[index.name] ?? {}), + ...beatIndex, ...index, indexes: [alias], }; diff --git a/x-pack/plugins/security_solution/server/search_strategy/index_fields/mock.ts b/x-pack/plugins/security_solution/server/search_strategy/index_fields/mock.ts index efb992a868f655..e5c502fe26f2cb 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/index_fields/mock.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/index_fields/mock.ts @@ -48,6 +48,22 @@ export const mockAuditbeatIndexField: FieldDescriptor[] = [ readFromDocValues: false, esTypes: [], }, + { + name: 'agent.user.name', + searchable: true, + type: 'string', + aggregatable: true, + readFromDocValues: false, + esTypes: [], + }, + { + name: 'client.as.number.text', + searchable: true, + type: 'string', + aggregatable: true, + readFromDocValues: false, + esTypes: [], + }, ]; export const mockFilebeatIndexField: FieldDescriptor[] = [