how to generate classes out of the json schema - java

I have a json schema from which I need to generate java classes
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://schema.softsense.io/analysis/vulnerabilities/v1alpha1/vulnerabilities.json",
"title": "Vulnerabilities",
"description": "SoftSense Vulnerabilities analysis schema v1alpha3",
"type": "object",
"allOf": [ { "$ref": "https://schema.softsense.io/analysis/v1alpha3/base.json" } ],
"properties": {
"vulnerabilities": {
"items": {
"$ref": "#/definitions/Vulnerability"
},
"type": "array"
}
},
"oneOf": [{ "required": ["vulnerabilities"] }, { "required": ["error"] }],
"definitions": {
"Vulnerability": {
"required": [
"id",
"description",
"sources"
],
"properties": {
"id": {
"description": "Identifier for the vulnerability, such as a CVE identifier (CVE-2021-12345).",
"type": "string"
},
"published": {
"description": "UTC time when the vulnerability was published",
"type": "string",
"format": "date-time"
},
"updated": {
"description": "UTC time when the vulnerability was updated",
"type": "string",
"format": "date-time"
},
"description": {
"description": "Description of the vulnerability",
"type": "string"
},
"sources": {
"description": "The collection of backing vulnerability sources that listed this vulnerability for the software component",
"items": {
"type": "string"
},
"type": "array"
},
"cwes": {
"description": "The collection of Common Weakness Enumeration (CWE) identifiers that characterize the vulnerability.",
"items": {
"$ref": "#/definitions/CWE"
},
"type": "array"
},
"references": {
"description": "External URLs related to the vulnerability, such as issue trackers, mailing list discussions, commits, or patches.",
"items": {
"$ref": "#/definitions/Reference"
},
"type": "array"
},
"impact": {
"description": "What impact this vulnerability has",
"$ref": "#/definitions/Impact"
}
},
"type": "object"
},
"Impact": {
"properties": {
"metricV3": {
"$ref": "#/definitions/ImpactMetricV3"
},
"metricV2": {
"$ref": "#/definitions/ImpactMetricV2"
},
"*": {
"type": "object"
}
},
"type": "object"
},
"ImpactMetricV3": {
"properties": {
"cvssV3": {
"$ref": "#/definitions/CVSSv3"
},
"exploitabilityScore": {
"type": "number"
},
"impactScore": {
"type": "number"
}
}
},
"CVSSv3": {
"required": [
"version",
"vectorString",
"baseScore",
"baseSeverity"
],
"properties": {
"version": {
"type": "string"
},
"vectorString": {
"type": "string"
},
"attackVector": {
"type": "string"
},
"attackComplexity": {
"type": "string"
},
"privilegesRequired": {
"type": "string"
},
"userInteraction": {
"type": "string"
},
"scope": {
"type": "string"
},
"confidentialityImpact": {
"type": "string"
},
"integrityImpact": {
"type": "string"
},
"availabilityImpact": {
"type": "string"
},
"baseScore": {
"type": "number"
},
"baseSeverity": {
"type": "string"
},
"exploitCodeMaturity": {
"type": "string"
},
"remediationLevel": {
"type": "string"
},
"reportConfidence": {
"type": "string"
},
"temporalScore": {
"type": "number"
},
"temporalSeverity": {
"type": "string"
},
"confidentialityRequirement": {
"type": "string"
},
"integrityRequirement": {
"type": "string"
},
"availabilityRequirement": {
"type": "string"
},
"modifiedAttackVector": {
"type": "string"
},
"modifiedAttackComplexity": {
"type": "string"
},
"modifiedPrivilegesRequired": {
"type": "string"
},
"modifiedUserInteraction": {
"type": "string"
},
"modifiedScope": {
"type": "string"
},
"modifiedConfidentialityImpact": {
"type": "string"
},
"modifiedIntegrityImpact": {
"type": "string"
},
"modifiedAvailabilityImpact": {
"type": "string"
},
"environmentalScore": {
"type": "number"
},
"environmentalSeverity": {
"type": "string"
}
},
"type": "object"
},
"ImpactMetricV2": {
"required": [
"cvssV2",
"severity",
"exploitabilityScore",
"impactScore",
"obtainAllPrivilege",
"obtainUserPrivilege",
"obtainOtherPrivilege",
"userInteractionRequired"
],
"properties": {
"cvssV2": {
"$ref": "#/definitions/CVSSv2"
},
"severity": {
"type": "string"
},
"exploitabilityScore": {
"type": "number"
},
"impactScore": {
"type": "number"
},
"acInsufInfo": {
"type": "boolean"
},
"obtainAllPrivilege": {
"type": "boolean"
},
"obtainUserPrivilege": {
"type": "boolean"
},
"obtainOtherPrivilege": {
"type": "boolean"
},
"userInteractionRequired": {
"type": "boolean"
}
},
"type": "object"
},
"CVSSv2": {
"required": [
"version",
"vectorString",
"baseScore"
],
"properties": {
"version": {
"type": "string"
},
"vectorString": {
"type": "string"
},
"accessVector": {
"type": "string"
},
"accessComplexity": {
"type": "string"
},
"authentication": {
"type": "string"
},
"confidentialityImpact": {
"type": "string"
},
"integrityImpact": {
"type": "string"
},
"availabilityImpact": {
"type": "string"
},
"baseScore": {
"type": "number"
},
"exploitability": {
"type": "string"
},
"remediationLevel": {
"type": "string"
},
"reportConfidence": {
"type": "string"
},
"temporalScore": {
"type": "number"
},
"collateralDamagePotential": {
"type": "string"
},
"targetDistribution": {
"type": "string"
},
"confidentialityRequirement": {
"type": "string"
},
"integrityRequirement": {
"type": "string"
},
"availabilityRequirement": {
"type": "string"
},
"environmentalScore": {
"type": "number"
}
},
"type": "object"
},
"CWE": {
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
}
},
"type": "object"
},
"Reference": {
"required": [
"url"
],
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
}
},
"type": "object"
}
}
}
I am trying to use the jsonschema2pojo as under.
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.4.34</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>com.test.gen</targetPackage>
<useCommonsLang3>true</useCommonsLang3>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
For some reason I get the following error when i use mvn generate-sources
[ERROR] Failed to execute goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.1.1:generate (default) on project hsk: Execution default of goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.1.1:generate failed: String index out of range: 0 -> [Help 1]
Any help is highly appreciated
Regards,

Related

Optional Properties json schema

the items are only required for the order_type: ORDER, but I can't make a conditional that only requires this property for that specific case, that is, if any order_type different from ORDER comes without items it can be validated correctly, but if an ORDER comes without them I mark it incorrectly.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Validaciones sobre el esquema Order",
"type": "object",
"properties": {
"warehouse_id": {
"type": [
"string"
]
},
"operation_type": {
"type": [
"string"
]
},
"order_id": {
"type": [
"number"
]
},
"items": {
"type": [
"array"
],
"minItems": 1,
"items": {
"type": [
"object"
],
"properties": {
"sku": {
"type": [
"string"
],
"minLength": 1,
"maxLength": 50
},
"quantity": {
"type": [
"integer"
],
"minimum": 1
}
},
"required": [
"sku",
"quantity"
],
"additionalProperties": false
}
},
"attributes": {
"type": [
"object"
],
"properties": {
"order_type": {
"type": [
"string"
],
"enum": [
"ORDER",
"TRANSFER",
"WITHDRAWAL",
"DISPOSAL",
"FRESH"
]
},
"etd": {
"type": [
"string"
],
"pattern": "^(\\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(?:T)(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])(?:Z)$"
},
"volume": {
"type": [
"integer", "null"
],
"minimum": 0
},
"typology": true
},
"required": [
"order_type"
],
"allOf": [
{
"if": {
"properties": {
"order_type": {
"const": "ORDER"
}
},
"required": [
"order_type",
"items"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true,
"typology": {
"type": [
"string", "null"
],
"enum": [
"CONVEYABLE",
"NON_CONVEYABLE"
]
}
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "TRANSFER"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "WITHDRAWAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "DISPOSAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
}
]
}
},
"required": [
"warehouse_id",
"operation_type",
"attributes"
],
"additionalProperties": false
}
try to make a conditional with an if at the end of the properties like this
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Validaciones sobre el esquema Order",
"type": "object",
"properties": {
"warehouse_id": {
"type": [
"string"
]
},
"operation_type": {
"type": [
"string"
]
},
"order_id": {
"type": [
"number"
]
},
"items": {
"type": [
"array"
],
"minItems": 1,
"items": {
"type": [
"object"
],
"properties": {
"sku": {
"type": [
"string"
],
"minLength": 1,
"maxLength": 50
},
"quantity": {
"type": [
"integer"
],
"minimum": 1
}
},
"required": [
"sku",
"quantity"
],
"additionalProperties": false
}
},
"attributes": {
"type": [
"object"
],
"properties": {
"order_type": {
"type": [
"string"
],
"enum": [
"ORDER",
"TRANSFER",
"WITHDRAWAL",
"DISPOSAL",
"FRESH"
]
},
"etd": {
"type": [
"string"
],
"pattern": "^(\\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(?:T)(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])(?:Z)$"
},
"volume": {
"type": [
"integer", "null"
],
"minimum": 0
},
"typology": true
},
"required": [
"order_type"
],
"allOf": [
{
"if": {
"properties": {
"order_type": {
"const": "ORDER"
}
},
"required": [
"order_type",
"items"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true,
"typology": {
"type": [
"string", "null"
],
"enum": [
"CONVEYABLE",
"NON_CONVEYABLE"
]
}
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "TRANSFER"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "WITHDRAWAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "DISPOSAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
}
]
}
},
"allOf": [
{
"if": {
"properties": {
"order_type": {
"const": "ORDER"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"items": true,
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd",
"items"
],
"additionalProperties": false
}
}
],
"required": [
"warehouse_id",
"operation_type",
"attributes"
],
"additionalProperties": false
}
this request should be marked as incorrect, cause dont have any items, that are required:
{
"warehouse_id": "ARTW01",
"operation_type": "outbound",
"order_id": 41789301078,
"attributes": {
"volume": 1350,
"etd": "2022-11-11T18:25:00Z",
"order_type": "ORDER"
}
}
Here's the assertion you described with all the unrelated parts removed. The trick is that the if need to describe the nested path to the value being checked.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"attributes": {
"type": "object",
"properties": {
"order_type": { "enum": ["ORDER", "TRANSFER", "WITHDRAWAL", "DISPOSAL", "FRESH"] }
},
"required": ["order_type"]
},
"items": { "type": "array" }
},
"allOf": [
{
"if": {
"type": "object",
"properties": {
"attributes": {
"type": "object",
"properties": {
"order_type": { "const": "ORDER" }
},
"required": ["order_type"]
}
},
"required": ["attributes"]
},
"then": { "required": ["items"] }
}
]
}

Error while inserting data into big query

I am getting the following error while inserting data programmatically into big query:
Conversion from bool to std::string is unsupported
I am new to BigQuery, So not sure what that means.
Here is the json that I am trying to insert:
{
"metadata": {
"projectName": "mtech-commonsvc-checkout-poc",
"dataSet": "
",
"tableName": "ARCHIVED_MESSAGE",
"clientId": "OES-GCP",
"transactionId": "11111898989",
"operationName": "INSERT",
"timeStamp": "2022-01-17T06:47:04.029257",
"sourceTableColumnCount": "50",
"callbackUrl": null,
"IS_DEL":null,
"GBQ_PARTITION_DATE": "2022-01-17T06:47:04.029257",
"GBQ_CREATED_TS":"2022-01-17T06:47:04.029257",
"ENVNAME":"DEV"
},
"data": [
...
...
...
{
"name": "MAIL_TEXT",
"value": null,
"type": "STRING"
},
{
"name": "MAIL_HTML",
"value": null,
"type": "STRING"
},
{
"name": "MESSAGE_RECEIVED_TIME",
"value": "2022-01-17T06:47:04.029257",
"type": "TIMESTAMP"
},
{
"name": "CREATED",
"value": "2022-01-17T06:47:04.029257",
"type": "TIMESTAMP"
},
{
"name": "LAST_UPDATED",
"value": "2022-01-17T06:47:04.029257",
"type": "TIMESTAMP"
},
{
"name": "MAIL_DELIVERY_TYPE",
"value": "E",
"type": "STRING"
},
{
"name": "ORIGINAL_MESSAGE_TEXT",
"value": null,
"type": "STRING"
},
{
"name": "ENHANCE_PAYLOAD",
"value": null,
"type": "STRING"
}
...
...
]
}
Any suggestions on how to debug this? I couldn't find anything specific to this error online.
The error, though, mentions the field is_del, which is present in JSON. I tried removing that
but still got the same error.

How do I determine why the getters and setters of POJOs generated from an AVSC file are not present?

I am using the Maven Avro plugin to generate POJOs from an AVSC file. Unfortunately, the top-most class that is generated from this file - loanInitiate - does not appear to contain any of the getters and setters needed for the other structures within the schema.
The POJOs that are generated for the child nodes do have the expected getters and setters. For example, the Customer class is generated and has a getNameBase() method.
I have tried editing this file in a variety of ways - changing structure, etc. - but I keep running into situations where the format is not valid.
Why would some of the getters and setters be generated and not others?
The Avro schema file is defined as follows:
{
"fields": [
{
"name": "loanInitiate",
"type": [
{
"type": "record",
"name": "eventheader",
"fields": [
{
"name": "eventType",
"type": "string",
"doc": "Loan"
},
{
"name": "eventSubtype",
"type": "string",
"doc": "Initiate"
},
{
"name": "eventDateTime",
"type": "string"
},
{
"name": "eventGeneratedDateTime",
"type": "string"
},
{
"name": "eventCorrelationId",
"type": [
"string",
"null"
]
},
{
"name": "eventRequestId",
"type": [
"string",
"null"
]
},
{
"name": "eventSourceDescription",
"type": [
"string",
"null"
]
},
{
"name": "eventSource",
"type": [
"string",
"null"
],
"doc": "The producer of this message."
},
{
"name": "eventInitiator",
"type": [
"string",
"null"
]
},
{
"name": "eventBatchGroupId",
"type": [
"string",
"null"
],
"doc": "BatchGroupID represents the GUID value given to each individual message which is part of a single batch."
},
{
"name": "eventBatchRecordCountTotal",
"type": [
"string",
"null"
],
"doc": "BatchRecordCountTotal provides the total number of messages belonging to a single batch."
}
]
},
{
"type": "array",
"name": "customer",
"items": {
"name": "customer",
"type": "record",
"fields": [
{
"name": "nameBase",
"type": {
"type": "record",
"name": "nameBase",
"fields": [
{
"name": "givenName",
"type": "string"
},
{
"name": "otherGivenName",
"type": [
"string",
"null"
]
},
{
"name": "fullName",
"type": "string"
},
{
"name": "suffix",
"type": [
"string",
"null"
]
},
{
"name": "surname",
"type": "string"
},
{
"name": "titlePrefix",
"type": [
"string",
"null"
]
}
]
}
},
{
"name": "party",
"type": {
"type": "record",
"name": "party",
"fields": [
{
"name": "parentEntityId",
"type": "string",
"doc": "The value of this field should equal the value the id field of the parent object."
},
{
"name": "partyRole",
"type": {
"type": "record",
"name": "partyRole",
"fields": [
{
"name": "code",
"type": {
"name": "code",
"type": "enum",
"symbols": [
"INSD",
"OWNR",
"PPAY",
"RCP"
]
}
},
{
"name": "subCode",
"type": {
"name": "subCode",
"type": "enum",
"symbols": [
"PRMR",
"LIST",
"BEN",
"DRBR",
"JNT"
]
}
}
]
}
}
]
}
},
{
"name": "id",
"type": "string",
"doc": "This is the identifier for an instance of customer, which can be related to from other objects."
}
]
}
},
{
"name": "bankAccount",
"type": "record",
"doc": "This object represents the bank account information, required for loan disbursements via ACH.",
"fields": [
{
"name": "accountType",
"type": {
"name": "accountType",
"type": "enum",
"symbols": [
"CHKNG",
"SVNG"
]
}
},
{
"name": "fullName",
"type": "string"
},
{
"name": "bankName",
"type": "string"
},
{
"name": "accountNumber",
"type": "string"
},
{
"name": "routingNumber",
"type": "string"
}
]
},
{
"type": "record",
"name": "trackingeventdetails",
"fields": [
{
"name": "workEventIdent",
"type": [
"string",
"null"
],
"doc": "This field will be populated based on the creation of a tracking work event. This field value holds the key for that particular event."
},
{
"name": "applicationId",
"type": "string"
},
{
"name": "divisionCode",
"type": "string"
},
{
"name": "departmentCode",
"type": "string"
},
{
"name": "workEventNumber",
"type": "int"
},
{
"name": "longComment",
"type": "string"
},
{
"name": "actualEventDate",
"type": "string"
},
{
"name": "priorityCode",
"type": "string"
},
{
"name": "contactTypeCode",
"type": "string"
},
{
"name": "receivedDate",
"type": "string"
},
{
"name": "shortComment",
"type": "string"
},
{
"name": "lastUpdatedBy",
"type": "string"
},
{
"name": "loggedByIdent",
"type": "string"
},
{
"name": "resourceId",
"type": "string"
},
{
"name": "requestOrTypeCode",
"type": "string"
},
{
"name": "serviceChannelSourceCode",
"type": "string"
},
{
"name": "nigoCode",
"type": "string"
},
{
"name": "imageAvailableIndicator",
"type": "string"
},
{
"name": "completionIndicator",
"type": "string"
}
]
},
{
"type": "record",
"name": "policy",
"fields": [
{
"name": "id",
"type": "int"
},
{
"name": "number",
"type": "long"
},
{
"name": "agreementNumberPrefix",
"type": "string"
},
{
"name": "agreementNumberSuffix",
"type": "string"
},
{
"name": "adminSystem",
"type": "string"
}
]
},
{
"type": "record",
"name": "loantransactiondetails",
"doc": "This represents the values specific to the loan transaction.",
"fields": [
{
"name": "transactionAmount",
"type": "string",
"doc": "The amount of the loan."
},
{
"name": "transactionType",
"type": "string"
},
{
"name": "transferAmount",
"type": {
"name": "transferAmount",
"type": "enum",
"symbols": [
"Max",
"Other"
]
}
}
]
}
]
}
],
"type": "record",
"namespace": "com.stream.process",
"name": "loanInitiate"
}

How to filter ElasticSearch results basis the field value?

Below is my example search response with 4 results retrieved.
{
"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"
]
}
}
]
}
}
Now, I want to filter the above search results basis the specific "dir" field value as per the below criteria.
Include the search result in the response if and only if:
If "dir" field value equals to either of: "/shared" or "/private/hitesh"
Else if "dir" field value starts with either of: "/shared/" or
"/private/hitesh/"
How can I achieve the above functionality in ElasticSearch?
PS: Below is my example mapping.
{
"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"
}
}
}
}
}
}
}
}
Try this query:
{
"query": {
"bool": {
"should": [
{
"term": {
"dir.raw": {
"value": "/shared"
}
}
},
{
"term": {
"dir.raw": {
"value": "/private/hitesh"
}
}
},
{
"match_phrase_prefix": {
"dir.raw": "/shared"
}
},
{
"match_phrase_prefix": {
"dir.raw": "/private/hitesh"
}
}
]
}
}
}

elasticsearch nested filters are not working as expected

I have documents like this in the elasticsearch:
{
"_index": "4ccda045-3958-4773-bb34-7af26fa52f4e",
"_type": "jira",
"_id": "BIGHALF-23",
"_score": 1,
"_source": {
"Issue Key": "BIGHALF-23",
"Issuetype Name": "Sub-task",
"Project Name": "Big_Half ",
"Project ID": "10500",
"Project Key": "BIGHALF",
"Workratio": -1,
"Watch Count": 1,
"Created": "2015-10-08T13:12:47",
"Priority": "Medium",
"Assignee Name": "german.solis",
"Assignee EmailAddress": "german.solis#bighalf.io",
"Assignee DisplayName": "German Solis",
"Is Assignee Active": "true",
"Assigne TimeZone": "America/Chicago",
"Updated": "2015-10-19T19:21:22",
"Issue Status": "Done",
"sprint": [{
"Sprint ID": "20",
"Sprint State": "CLOSED",
"Sprint Name": "Sprint 11",
"Sprint StartDate": "2015-10-05T01:43:29",
"Sprint EndDate": "2015-10-12T01:43:00",
"Sprint CompleteDate": "2015-10-13T14:31:47"
}, {
"Sprint ID": "23",
"Sprint State": "CLOSED",
"Sprint Name": "Sprint 1",
"Sprint StartDate": "2015-10-19T01:47:18",
"Sprint EndDate": "2015-10-26T01:47:00",
"Sprint CompleteDate": "2015-10-24T23:55:22"
}, {
"Sprint ID": "24",
"Sprint State": "CLOSED",
"Sprint Name": "Sprint 2",
"Sprint StartDate": "2015-10-26T11:21:21",
"Sprint EndDate": "2015-11-01T11:21:00",
"Sprint CompleteDate": "2015-11-01T23:06:45"
}],
"Creator Name": "fernando.velazquez",
"Creator EmailAddress": "fernando.velazquez#bighalf.io",
"Creator DisplayName": "fernando.velazquez",
"Creator Active": "false",
"Creator TimeZone": "America/Chicago",
"Reporter Name": "fernando.velazquez",
"Reporter EmailAddress": "fernando.velazquez#bighalf.io",
"Reporter DisplayName": "fernando.velazquez",
"Reporter Active": "false",
"Reporter TimeZone": "America/Chicago",
"Aggregate Progress": 0,
"Aggregate Progress Total": 0,
"Progress": 0,
"Progress Total": 0
}
}
Am applying filter like this using transport client.
{
"bool" : {
"must" : [ {
"nested" : {
"query" : {
"bool" : {
"must" : {
"terms" : {
"sprint.Sprint Name" : [ "Sprint 9" ]
}
}
}
},
"path" : "sprint"
}
}, {
"terms" : {
"Assignee DisplayName" : [ "Mateen Khan" ]
}
} ]
}
}
Even after applying filter Am getting data of other sprints also. which means am getting data for "sprint 7" as well as other sprints also. Am using transport client and also Am performing few complex aggregations with in the same query.
Mappings:
{
"4ccda045-3958-4773-bb34-7af26fa52f4e": {
"mappings": {
"jira": {
"properties": {
"Aggregate Progress": {
"type": "long"
},
"Aggregate Progress Total": {
"type": "long"
},
"Aggregate Progress percent": {
"type": "long"
},
"Aggregate Time Estimate": {
"type": "long"
},
"Aggregate Time Original Estimate": {
"type": "long"
},
"Aggregate Timespent": {
"type": "long"
},
"Assigne TimeZone": {
"type": "string",
"index": "not_analyzed"
},
"Assignee DisplayName": {
"type": "string",
"index": "not_analyzed"
},
"Assignee EmailAddress": {
"type": "string",
"index": "not_analyzed"
},
"Assignee Name": {
"type": "string",
"index": "not_analyzed"
},
"Created": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Creator Active": {
"type": "string",
"index": "not_analyzed"
},
"Creator DisplayName": {
"type": "string",
"index": "not_analyzed"
},
"Creator EmailAddress": {
"type": "string",
"index": "not_analyzed"
},
"Creator Name": {
"type": "string",
"index": "not_analyzed"
},
"Creator TimeZone": {
"type": "string",
"index": "not_analyzed"
},
"Description": {
"type": "string",
"index": "not_analyzed"
},
"Is Assignee Active": {
"type": "string",
"index": "not_analyzed"
},
"Issue Key": {
"type": "string",
"index": "not_analyzed"
},
"Issue Status": {
"type": "string",
"index": "not_analyzed"
},
"Issuetype Name": {
"type": "string",
"index": "not_analyzed"
},
"Priority": {
"type": "string",
"index": "not_analyzed"
},
"Progress": {
"type": "long"
},
"Progress Percent": {
"type": "long"
},
"Progress Total": {
"type": "long"
},
"Project ID": {
"type": "string",
"index": "not_analyzed"
},
"Project Key": {
"type": "string"
},
"Project Name": {
"type": "string",
"index": "not_analyzed"
},
"Reporter Active": {
"type": "string",
"index": "not_analyzed"
},
"Reporter DisplayName": {
"type": "string",
"index": "not_analyzed"
},
"Reporter EmailAddress": {
"type": "string",
"index": "not_analyzed"
},
"Reporter Name": {
"type": "string",
"index": "not_analyzed"
},
"Reporter TimeZone": {
"type": "string",
"index": "not_analyzed"
},
"Sprint Issue Points": {
"type": "long"
},
"Summary": {
"type": "string",
"index": "not_analyzed"
},
"Time Estimate": {
"type": "long"
},
"Time Original Estimate": {
"type": "long"
},
"Time Tracking Original Estimate": {
"type": "string",
"index": "not_analyzed"
},
"Time Tracking Original Estimate Seconds": {
"type": "long"
},
"Time Tracking Remaining Estimate": {
"type": "string",
"index": "not_analyzed"
},
"Time Tracking Remaining Estimate Seconds": {
"type": "long"
},
"Time Tracking Time Spent": {
"type": "string",
"index": "not_analyzed"
},
"Time Tracking Time Spent Seconds": {
"type": "long"
},
"Updated": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Watch Count": {
"type": "long"
},
"Workratio": {
"type": "long"
},
"sprint": {
"type": "nested",
"properties": {
"Sprint CompleteDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Sprint EndDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Sprint ID": {
"type": "string",
"index": "not_analyzed"
},
"Sprint Name": {
"type": "string",
"index": "not_analyzed"
},
"Sprint StartDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Sprint State": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
Can you please try replacing terms in must clause by match?
{
"bool" : {
"must" : [ {
"nested" : {
"query" : {
"bool" : {
"must" : {
"match" : {
"sprint.Sprint Name" : [ "Sprint 9" ]
}
}
}
},
"path" : "sprint"
}
}, {
"terms" : {
"Assignee DisplayName" : [ "Mateen Khan" ]
}
} ]
}
}

Categories

Resources