OpenAPI v3, how to hide objects in "Schemas" section - swagger

I'm using OpenAPI v3 to create my API docs and having them hosted on app.swaggerhub.com
Is there a way to hide an item from showing up in the Schemas section at the bottom? The real API has dozens of Schema objects, so it'd be very helpful to hide some of them.
Example:
Running this on https://editor-next.swagger.io/
{
"openapi": "3.0.3",
"info": {
"title": "Swagger Petstore - OpenAPI 3.0",
"description": "example",
"version": "1.0.11"
},
"servers": [
{
"url": "https://petstore3.swagger.io/api/v3"
}
],
"paths": {
"/pet": {
"post": {
"summary": "Add a new pet to the store",
"description": "Add a new pet to the store",
"operationId": "addPet",
"requestBody": {
"description": "Create a new pet in the store",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Order": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 10
},
"petId": {
"type": "integer",
"format": "int64",
"example": 198772
},
"quantity": {
"type": "integer",
"format": "int32",
"example": 7
},
"shipDate": {
"type": "string",
"format": "date-time"
},
"status": {
"type": "string",
"description": "Order Status",
"example": "approved",
"enum": [
"placed",
"approved",
"delivered"
]
},
"complete": {
"type": "boolean"
}
},
"xml": {
"name": "order"
}
},
"Customer": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 100000
},
"username": {
"type": "string",
"example": "fehguy"
},
"address": {
"type": "array",
"xml": {
"name": "addresses",
"wrapped": true
},
"items": {
"$ref": "#/components/schemas/Address"
}
}
},
"xml": {
"name": "customer"
}
},
"Address": {
"type": "object",
"properties": {
"street": {
"type": "string",
"example": "437 Lytton"
},
"city": {
"type": "string",
"example": "Palo Alto"
},
"state": {
"type": "string",
"example": "CA"
},
"zip": {
"type": "string",
"example": "94301"
}
},
"xml": {
"name": "address"
}
},
"Category": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 1
},
"name": {
"type": "string",
"example": "Dogs"
}
},
"xml": {
"name": "category"
}
},
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 10
},
"username": {
"type": "string",
"example": "theUser"
},
"firstName": {
"type": "string",
"example": "John"
},
"lastName": {
"type": "string",
"example": "James"
},
"email": {
"type": "string",
"example": "john#email.com"
},
"password": {
"type": "string",
"example": "12345"
},
"phone": {
"type": "string",
"example": "12345"
},
"userStatus": {
"type": "integer",
"description": "User Status",
"format": "int32",
"example": 1
}
},
"xml": {
"name": "user"
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
},
"xml": {
"name": "tag"
}
},
"Pet": {
"required": [
"name",
"photoUrls"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 10
},
"name": {
"type": "string",
"example": "doggie"
},
"category": {
"$ref": "#/components/schemas/Category"
},
"photoUrls": {
"type": "array",
"xml": {
"wrapped": true
},
"items": {
"type": "string",
"xml": {
"name": "photoUrl"
}
}
},
"tags": {
"type": "array",
"xml": {
"wrapped": true
},
"items": {
"$ref": "#/components/schemas/Tag"
}
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
}
},
"xml": {
"name": "pet"
}
},
"ApiResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"type": {
"type": "string"
},
"message": {
"type": "string"
}
},
"xml": {
"name": "##default"
}
}
},
"requestBodies": {
"Pet": {
"description": "Pet object that needs to be added to the store",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
}
},
"UserArray": {
"description": "List of user object",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
},
"securitySchemes": {
"petstore_auth": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://petstore3.swagger.io/oauth/authorize",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
},
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
}
}
}
}
...this gets generated:
In this example, I'd like to hide a few of the schema items from view (like Customer or Address).
Note: I'm not self-hosting, so I'm hoping there's a tag I can put into the YAML or JSON.
Thanks,
Ryan

Related

Complex Nested JSON Conversion to Data Table without creating class in C#

{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Title",
"type": "object",
"properties": {
"location": {
"type": "string"
},
"dagno": {
"type": "string"
},
"pattano": {
"type": "string"
},
"pattatype": {
"type": "string"
},
"landclass": {
"type": "string"
},
"bigha": {
"type": "string"
},
"katha": {
"type": "string"
},
"lessa": {
"type": "string"
},
"pid": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"pdarid": {
"type": "string"
},
"pdarname": {
"type": "string"
},
"pdarfather": {
"type": "string"
}
},
"required": [
"pdarid",
"pdarname",
"pdarfather"
]
}
]
}
},
"required": [
"location",
"dagno",
"pattano",
"pattatype",
"landclass",
"bigha",
"katha",
"lessa",
"pid"
]
}

Springfox error "Unable to find a model that matches key" for {namespace='java.lang', name='Class�ConstraintValidator�object,object��'}

I'm getting these error messages in logs:
[12:15 11:48:20.957] [ERROR][request id: ffdedde3-f147-4fc2-9f9f-ad0c76c1a868][springfox.documentation.swagger2.mappers.ReferenceModelSpecificationToPropertyConverter] - Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='java.lang', name='Class�ConstraintValidator�object,object��'}, viewDiscriminator=com.test.entity.view.View$External, validationGroupDiscriminators=[], isResponse=true}
[12:15 11:48:20.957] [ERROR][request id: ffdedde3-f147-4fc2-9f9f-ad0c76c1a868][springfox.documentation.swagger2.mappers.ReferenceModelSpecificationToPropertyConverter] - Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='java.lang', name='Class�object�'}, viewDiscriminator=com.test.entity.view.View$External, validationGroupDiscriminators=[], isResponse=true}
[12:15 11:48:20.958] [ERROR][request id: ffdedde3-f147-4fc2-9f9f-ad0c76c1a868][springfox.documentation.swagger2.mappers.ReferenceModelSpecificationToPropertyConverter] - Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='java.lang', name='Class�Payload�'}, viewDiscriminator=com.test.entity.view.View$External, validationGroupDiscriminators=[], isResponse=true}
[12:15 11:48:20.991] [ERROR][request id: ffdedde3-f147-4fc2-9f9f-ad0c76c1a868][springfox.documentation.swagger2.mappers.ReferenceModelSpecificationToPropertyConverter] - Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='java.lang', name='Class�ConstraintValidator�object,object��'}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}
[12:15 11:48:20.991] [ERROR][request id: ffdedde3-f147-4fc2-9f9f-ad0c76c1a868][springfox.documentation.swagger2.mappers.ReferenceModelSpecificationToPropertyConverter] - Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='java.lang', name='Class�object�'}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}
[12:15 11:48:20.992] [ERROR][request id: ffdedde3-f147-4fc2-9f9f-ad0c76c1a868][springfox.documentation.swagger2.mappers.ReferenceModelSpecificationToPropertyConverter] - Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='java.lang', name='Class�Payload�'}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}
It seems as custom validation annotations are somehow involved and related to them fields are treated as models or smth.
Example:
#Target({ElementType.TYPE})
#Retention(RetentionPolicy.RUNTIME)
#Constraint(validatedBy = CardDocumentValidator.class)
#Documented
public #interface CardDocument {
String message();
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
public class CardDocumentValidator implements ConstraintValidator<CardDocument, TestEntity> {...}
I'm using Spring Boot 2.5.5 with springfox-boot-starter 3.0.0.
However I'm still on OpenApi 2.0, so I have configured the property springfox:documentation:swagger:use-model-v3: false, which helped me to get rid of similar errors.
In api-docs json among definitions:
"ConstraintDescriptor«object»": {
"type": "object",
"properties": {
"annotation": {
"type": "object"
},
"attributes": {
"type": "object"
},
"composingConstraints": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/ConstraintDescriptor«object»"
}
},
"constraintValidatorClasses": {
"type": "array",
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«ConstraintValidator«object,object»»'}"
}
},
"groups": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«object»'}"
}
},
"messageTemplate": {
"type": "string"
},
"payload": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«Payload»'}"
}
},
"reportAsSingleViolation": {
"type": "boolean"
},
"validationAppliesTo": {
"type": "string",
"enum": [
"IMPLICIT",
"PARAMETERS",
"RETURN_VALUE"
]
},
"valueUnwrapping": {
"type": "string",
"enum": [
"DEFAULT",
"SKIP",
"UNWRAP"
]
}
},
"title": "ConstraintDescriptor«object»"
},
"ConstraintDescriptor«object»DefaultView": {
"type": "object",
"properties": {
"annotation": {
"type": "object"
},
"attributes": {
"type": "object"
},
"composingConstraints": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/ConstraintDescriptor«object»DefaultView"
}
},
"constraintValidatorClasses": {
"type": "array",
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«ConstraintValidator«object,object»»'}"
}
},
"groups": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«object»'}"
}
},
"messageTemplate": {
"type": "string"
},
"payload": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«Payload»'}"
}
},
"reportAsSingleViolation": {
"type": "boolean"
},
"validationAppliesTo": {
"type": "string",
"enum": [
"IMPLICIT",
"PARAMETERS",
"RETURN_VALUE"
]
},
"valueUnwrapping": {
"type": "string",
"enum": [
"DEFAULT",
"SKIP",
"UNWRAP"
]
}
},
"title": "ConstraintDescriptor«object»DefaultView"
},
"ConstraintDescriptor«object»ExternalView": {
"type": "object",
"properties": {
"annotation": {
"type": "object"
},
"attributes": {
"type": "object"
},
"composingConstraints": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/ConstraintDescriptor«object»ExternalView"
}
},
"constraintValidatorClasses": {
"type": "array",
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«ConstraintValidator«object,object»»'}"
}
},
"groups": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«object»'}"
}
},
"messageTemplate": {
"type": "string"
},
"payload": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/Error-ModelName{namespace='java.lang', name='Class«Payload»'}"
}
},
"reportAsSingleViolation": {
"type": "boolean"
},
"validationAppliesTo": {
"type": "string",
"enum": [
"IMPLICIT",
"PARAMETERS",
"RETURN_VALUE"
]
},
"valueUnwrapping": {
"type": "string",
"enum": [
"DEFAULT",
"SKIP",
"UNWRAP"
]
}
},
"title": "ConstraintDescriptor«object»ExternalView"
},
"ConstraintValidator«object,object»": {
"type": "object",
"title": "ConstraintValidator«object,object»"
},
"ConstraintValidator«object,object»DefaultView": {
"type": "object",
"title": "ConstraintValidator«object,object»DefaultView"
},
"ConstraintValidator«object,object»ExternalView": {
"type": "object",
"title": "ConstraintValidator«object,object»ExternalView"
},
"ConstraintViolation": {
"type": "object",
"properties": {
"constraintDescriptor": {
"$ref": "#/definitions/ConstraintDescriptor«object»"
},
"executableParameters": {
"type": "array",
"items": {
"type": "object"
}
},
"executableReturnValue": {
"type": "object"
},
"invalidValue": {
"type": "object"
},
"leafBean": {
"type": "object"
},
"message": {
"type": "string"
},
"messageTemplate": {
"type": "string"
},
"propertyPath": {
"$ref": "#/definitions/Path"
},
"rootBean": {
"type": "object"
}
},
"title": "ConstraintViolation"
},
"ConstraintViolationDefaultView": {
"type": "object",
"properties": {
"constraintDescriptor": {
"$ref": "#/definitions/ConstraintDescriptor«object»DefaultView"
},
"executableParameters": {
"type": "array",
"items": {
"type": "object"
}
},
"executableReturnValue": {
"type": "object"
},
"invalidValue": {
"type": "object"
},
"leafBean": {
"type": "object"
},
"message": {
"type": "string"
},
"messageTemplate": {
"type": "string"
},
"propertyPath": {
"$ref": "#/definitions/PathDefaultView"
},
"rootBean": {
"type": "object"
}
},
"title": "ConstraintViolationDefaultView"
},
"ConstraintViolationExternalView": {
"type": "object",
"properties": {
"constraintDescriptor": {
"$ref": "#/definitions/ConstraintDescriptor«object»ExternalView"
},
"executableParameters": {
"type": "array",
"items": {
"type": "object"
}
},
"executableReturnValue": {
"type": "object"
},
"invalidValue": {
"type": "object"
},
"leafBean": {
"type": "object"
},
"message": {
"type": "string"
},
"messageTemplate": {
"type": "string"
},
"propertyPath": {
"$ref": "#/definitions/PathExternalView"
},
"rootBean": {
"type": "object"
}
},
"title": "ConstraintViolationExternalView"
},
Found the culprit :)
private Set validationErrors in one of the base entity classes.
So ConstraintViolation was added to Models and ConstraintDescriptor and its fields' classes which included:
private final List<Class<? extends ConstraintValidator<T, ?>>> constraintValidatorClasses;
private final Set<Class<?>> groups;
private final Set<Class<? extends Payload>> payloads;
Putting #JsonIgnore helped. Another way is to add #ApiModelProperty(hidden = true) which doesn't affect serialization by simply hiding the field from being documented.

Swagger-UI Maximum call stack size exceeded -> Backreference

When calling my swagger.json from the swagger-ui I get an error:
Maximum call stack size exceeded
I guess it is because I have
Token which has an owner of Type User
User which has a Token of Type Token
When using the online-version of the swagger editior it can resolve the types. How can I configure swagger to resolve the types correctly?
The full swagger.json
{
"swagger": "2.0",
"info": {
"description": "Descr",
"version": "1.0.0",
"title": "Skeleton"
},
"host": "1.1.1.1:11",
"basePath": "/api",
"tags": [{
"name": "auth"
}
],
"schemes": ["http"],
"paths": {
"/auth/local": {
"post": {
"tags": ["auth"],
"summary": "Authenticates User",
"description": "This auths only local users",
"operationId": "authenticateUser",
"consumes": ["application/json"],
"produces": ["application/json"],
"parameters": [{
"in": "body",
"name": "body",
"required": false,
"schema": {
"$ref": "#/definitions/Credentials"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/AuthResponse"
}
}
}
}
},
"/auth/ldap": {
"post": {
"tags": ["auth"],
"operationId": "authenticateLdapUser",
"produces": ["application/json"],
"parameters": [{
"in": "body",
"name": "body",
"required": false,
"schema": {
"$ref": "#/definitions/Credentials"
}
}
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
}
},
"definitions": {
"AuthResponse": {
"type": "object",
"properties": {
"issued": {
"type": "string",
"format": "date-time"
},
"responseType": {
"type": "string",
"enum": ["RESPONSE", "ERROR", "UNAUTHORIZED", "OK"]
},
"responseDescription": {
"type": "string"
},
"accessToken": {
"$ref": "#/definitions/Token"
},
"resourceName": {
"type": "string"
}
}
},
"Note": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"content": {
"type": "string"
},
"modified": {
"type": "string",
"format": "date-time"
}
}
},
"Token": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"expirationDate": {
"type": "string",
"format": "date-time"
},
"issued": {
"type": "string",
"format": "date-time"
},
"expired": {
"type": "boolean"
},
"owner": {
"$ref": "#/definitions/User"
}
}
},
"User": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
},
"email": {
"type": "string"
},
"displayName": {
"type": "string"
},
"notes": {
"type": "array",
"items": {
"$ref": "#/definitions/Note"
}
},
"accessToken": {
"$ref": "#/definitions/Token"
}
}
},
"Credentials": {
"type": "object",
"properties": {
"user": {
"type": "string"
},
"password": {
"type": "string"
}
}
}
}
}
I have the same problem and I removed format: date-time and the error is gone.
Still I don't know what causes the error. But without that format everything goes ok.
In FastAPI which uses Swagger UI, I was receiving the same error. I updated the FastAPI package to get the last version of Swagger UI and then set the value of 'syntaxHighlight' to False, like below:
app = FastAPI(swagger_ui_parameters={'syntaxHighlight': False})
Just search how you can set this param directly in Swagger UI. This may fix your issue.

Swagger 2.0 - Inconsistent Results From Swagger Source

Swagger source below. When I run the swagger-tools validator, I receive no errors. When I load this in the editor, I see output but it is incorrect - it shows wrong types, and an incomplete Member object. When I try to use the code generator cli java tool, I get the following errors:
711 [main] ERROR io.swagger.models.properties.PropertyBuilder - no property for null, null
712 [main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null}
822 [main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name null
822 [main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
"type" : "array"
}
{
"swagger": "2.0",
"info": {
"title": "V1 Inmar CRM API",
"description": "CRM API",
"version": "1.0.0"
},
"produces": ["application/json"],
"basePath": "/v1",
"paths": {
"/member": {
"get": {
"x-swagger-router-controller": "member",
"tags": ["member"],
"operationId": "GetMember",
"parameters": [
{ "$ref": "#/parameters/x-inmar-rest-api-key" },
{ "$ref": "#/parameters/x-inmar-memberID" }
],
"responses": {
"200": {
"description": "success",
"schema": { "$ref": "#/definitions/Member" }
}
}
},
"post": {
"x-swagger-route-controller": "member",
"tags": ["member"],
"operationId": "PostMember",
"parameters": [
{ "$ref": "#/parameters/x-inmar-rest-api-key" },
{ "$ref": "#/parameters/x-inmar-memberID" },
{ "$ref": "#/parameters/member" }
],
"responses": {
"200": { "$ref": "#/responses/generic-200" }
}
}
}
},
"parameters": {
"x-inmar-rest-api-key": {
"name": "X-Inmar-REST-API-Key",
"description": "API Access Key.",
"in": "header",
"required": true,
"type": "string"
},
"x-inmar-memberID": {
"name": "X-Inmar-MemberID",
"description": "Unique ID for member.",
"in": "header",
"required": true,
"type": "string"
},
"member": {
"description": "member object",
"in": "body",
"name": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Member"
}
}
},
"responses": {
"generic-200": {
"description": "Success"
}
},
"definitions": {
"Member": {
"description": "member",
"type": "object",
"properties": {
"active": {
"type": "boolean",
"default": true
},
"identity": {
"type": "object",
"required": [
"user_id"
],
"properties": {
"user_id": {
"type": "string",
"maxLength": 50,
"format": "email"
},
"password": {
"type": "string",
"minLength": 8,
"maxLength": 20
},
"proxy_id": {
"type": "integer"
}
}
},
"pii": {
"type": "object",
"description": "personally_identifiable_information.",
"properties": {
"alt_email": {
"type": "string",
"description": "Secondary email addresses that may or may not match the id.",
"format": "email"
},
"first_name": {
"type": "string",
"minLength": 1,
"maxLength": 25
},
"last_name": {
"type": "string",
"minLength": 1,
"maxLength": 25
},
"primary_address_one": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_two": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_city": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_state": {
"type": "string",
"minLength": 2,
"maxLength": 2,
"description": "US states and US territories and Canadian provinces.",
"enum": [
"AA",
"AB",
"AE",
"AK",
"AL",
"AP",
"AR",
"AS",
"AZ",
"BC",
"CA",
"CO",
"CT",
"DC",
"DE",
"FL",
"FM",
"GA",
"GU",
"HI",
"IA",
"ID",
"IL",
"IN",
"KS",
"KY",
"LA",
"MA",
"MB",
"MD",
"ME",
"MH",
"MI",
"MN",
"MO",
"MP",
"MS",
"MT",
"NB",
"NC",
"ND",
"NE",
"NH",
"NJ",
"NL",
"NM",
"NS",
"NT",
"NU",
"NV",
"NY",
"OH",
"OK",
"ON",
"OR",
"PA",
"PE",
"PR",
"PW",
"QC",
"RI",
"SC",
"SD",
"SK",
"TN",
"TX",
"UK",
"UT",
"VA",
"VI",
"VT",
"WA",
"WI",
"WV",
"WY",
"YT"
]
},
"primary_address_postal_code": {
"type": "string",
"minLength": 5,
"maxLength": 10
},
"primary_address_country": {
"type": "string",
"enum": [
"US",
"CA"
]
},
"birthdate": {
"type": "string"
},
"language_preference": {
"type": "string"
},
"gender": {
"type": "string",
"enum": [
"male",
"female"
]
}
}
},
"profiles": {
"type": "array",
"items": {
"properties": {
"site_id": {
"type": "integer"
},
"survey_data": {
"type": "object",
"required": [
"survey_id",
"survey_responses"
],
"properties": {
"survey_id": {
"type": "integer",
"description": "Unique identifier of a profile survey."
},
"survey_responses": {
"type": "array",
"items": {
"required": [
"question_id",
"response_id",
"free_form_value"
],
"properties": {
"question_id": {
"type": "integer",
"description": "Unique identifier of a profile survey question."
},
"response_id": {
"type": "integer",
"description": "Unique identifier of a profile question response.",
"default": 0
},
"free_form_value": {
"type": "string",
"description": "Consumer free form response",
"default": ""
}
}
}
}
}
}
}
}
},
"optins": {
"type": "array",
"items": {
"$ref": "#/definitions/OptIn"
}
}
}
},
"OptIn": {
"description": "survey response",
"type": "object",
"properties":{
"optin_id": {
"type": "integer",
"description": "Unique identifier of an opt in question/choice. e.g. newsletter"
},
"optin_value": {
"type": "integer",
"enum": [ 0, 1 ],
"description": "Optin Response of 0=Optout and 1=Optin"
}
},
"required": [
"optin_id",
"optin_value"
]
}
}
}

My ES custom analyser is not used?

I'm using Elasticsearch and create an index with the following information for mapping and settings. The problem I have is that my field geography.locality which should use the 'name_analyser' doesn't seem to use it.
{
"index": "programs",
"body": {
"settings": {
"number_of_shards": 5,
"analysis": {
"filter": {
"elision": {
"type": "elision",
"articles": [
"l",
"m",
"t",
"qu",
"n",
"s",
"j",
"d"
]
},
"multi_words": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 10
},
"name_filter": {
"type": "edgeNGram",
"max_gram": 100,
"min_gram": 2
}
},
"tokenizer": {
"name_tokenizer": {
"type": "edgeNGram",
"max_gram": 100,
"min_gram": 2
}
},
"analyser": {
"name_analyser": { // <-- analyser I want to use on geography.locality
"tokenizer": "whitespace",
"type": "custom",
"filter": [
"lowercase",
"multi_words",
"name_filter",
"asciifolding"
]
},
"french": {
"tokenizer": "letter",
"filter": [
"asciifolding",
"lowercase",
"elision",
"stop"
]
},
"city_name": {
"type": "custom",
"tokenizer": "letter",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"program": {
"properties": {
"nid": {
"type": "integer",
"index": "not_analyzed"
},
"title": {
"type": "string"
},
"language": {
"type": "string",
"index": "not_analyzed"
},
"regulation": {
"type": "integer"
},
"sales_state": {
"type": "integer"
},
"enabled_dwell": {
"type": "boolean"
},
"enabled_invest": {
"type": "boolean"
},
"delivery_date": {
"type": "date"
},
"address": {
"properties": {
"country": {
"type": "string",
"index": "not_analyzed"
},
"locality": {
"type": "string",
"analyser": "name_analyser"
},
"postal_code": {
"type": "integer"
},
"thoroughfare": {
"type": "string",
"index": "not_analyzed"
},
"premise": {
"type": "string",
"index": "not_analyzed"
}
}
},
"location": {
"type": "geo_point"
},
"geography": {
"properties": {
"locality": {
"type": "string",
"analyser": "name_analyser" // ... here :-/
},
"department": {
"type": "string",
"index": "not_analyzed"
},
"region": {
"type": "string",
"index": "not_analyzed"
}
}
},
"lots": {
"type": "nested",
"include_in_all": false,
"properties": {
"lot_type": {
"type": "integer"
},
"rooms": {
"type": "integer"
},
"price_vat_inc": {
"type": "integer"
},
"price_reduced_vat_inc": {
"type": "integer"
},
"price_vat_ex": {
"type": "integer"
}
}
}
}
}
}
}
}
Here's the output given by ES for the mapping registered for this index.
{
"program": {
"properties": {
"address": {
"properties": {
"country": {
"index": "not_analyzed",
"type": "string"
},
"premise": {
"index": "not_analyzed",
"type": "string"
},
"locality": {
"type": "string"
},
"postal_code": {
"type": "integer"
},
"thoroughfare": {
"index": "not_analyzed",
"type": "string"
}
}
},
"sales_state": {
"type": "integer"
},
"nid": {
"type": "integer"
},
"language": {
"index": "not_analyzed",
"type": "string"
},
"title": {
"type": "string"
},
"enabled_invest": {
"type": "boolean"
},
"geo_point": {
"type": "string"
},
"lots": {
"include_in_all": false,
"type": "nested",
"properties": {
"rooms": {
"include_in_all": false,
"type": "integer"
},
"price_vat_inc": {
"include_in_all": false,
"type": "integer"
},
"price_vat_ex": {
"include_in_all": false,
"type": "integer"
},
"lot_type": {
"include_in_all": false,
"type": "integer"
},
"price_reduced_vat_inc": {
"include_in_all": false,
"type": "integer"
}
}
},
"enabled_dwell": {
"type": "boolean"
},
"delivery_date": {
"format": "dateOptionalTime",
"type": "date"
},
"regulation": {
"type": "integer"
},
"geography": {
"properties": {
"locality": {
"type": "string" // name_analyser should show up here right?????
},
"department": {
"index": "not_analyzed",
"type": "string"
},
"region": {
"index": "not_analyzed",
"type": "string"
}
}
},
"location": {
"type": "geo_point"
}
}
}
}
Does anybody knows what I am doing wrong? I'm kind of lost about this.
You have a typo :-), actually two:
"locality": {
"type": "string",
"analyser": "name_analyser"
},
in both address and geography. It should be analyzer not analyser (with an s).
Also, the same here:
"analyser": {
"name_analyser": {
"tokenizer": "whitespace",
...
I am guessing that the index exists and you are trying to update the settings with a new analyser. This is not permitted on a live index.
Do you have any errors when you submit the updated settings?
Have a look at this thread - Change settings and mappings on existing index in Elasticsearch
and here http://www.elastic.co/guide/en/elasticsearch/reference/1.x/indices-update-settings.html#update-settings-analysis

Resources