I have set up mongoosastic to index my documents to elastic search. The trouble is, despite the schema set, all fields are indexed.
My Schema:
id: { type: String, index: true },
title: String,
title_lower: { type: String, es_indexed: true, es_boost: 2.0 },
slug: String,
city: { type: String, es_indexed: true },
country: { type: String, es_indexed: true },
genre: [{ type: String, es_indexed: true }],
description: { type: String, es_indexed: true },
gallery: [{ title: String, images: { thumbnail: String, medium: String, full: String }}],
date: { start: String, end: String },
price: { min: Number, max: Number },
temperature: Number,
weather: String,
comments: [CommentSchema],
lineup: { type: [LineupSchema], es_indexed: true }
Here I want only title_lower, city, genre, description and lineup indexed. But checking elastic like: http://localhost:9200/events/_search I can see that all fields are added under _source.
Related
mapping: {
dynamic: 'strict',
properties: {
name: { type: 'text', index: false },
email: { type: 'keyword' },
phoneNumber: { type: 'text', index: false },
},
},
How to add the required field for name, email and phone number?
I have an address in my database that I've put into a location hash. The hash contains separate keys for streetAddress, city, state, and zipCode. I've nested the data like so in my graphql schema file:
location: {
streetAddress: {
type: String,
required: true,
unqiue: true
},
city: {
type: String,
required: true
},
state: {
type: String,
required: true
},
zipCode: {
type: Number,
required: true
}
}
And I've implemented the schema type like this:
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
id: {type: GraphQLID},
phoneNum: { type: GraphQLString },
location: {
streetAddress: { type: GraphQLString },
city: { type: GraphQLString },
state: { type: GraphQLString },
zipCode: { type: GraphQLInt }
}
...
However, I get an error message saying that the output type is undefined when I try to do a query in graphql:
"message": "The type of RestaurantType.location must be Output Type but got: undefined."
I believe I understand where the error is coming from; I'm assuming that it expects location to have a type as well. What would be the correct syntax for doing this/fixing this error message?
As you guessed, you cannot have nested fields like that. You need to create a separate type for every object in your schema. First create the type:
const Location = new GraphQLObjectType({
name: 'Location',
fields: () => ({
streetAddress: { type: GraphQLString },
city: { type: GraphQLString },
state: { type: GraphQLString },
zipCode: { type: GraphQLInt }
}),
})
Then use it:
const Restaurant = new GraphQLObjectType({
name: 'Restaurant',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
location: { type: Location },
}),
})
or if you don't need to reuse the type, you can define it inline like this:
const Restaurant = new GraphQLObjectType({
name: 'Restaurant',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
location: {
type: new GraphQLObjectType({
name: 'Location',
fields: () => ({
streetAddress: { type: GraphQLString },
city: { type: GraphQLString },
state: { type: GraphQLString },
zipCode: { type: GraphQLInt }
}),
})
},
}),
})
I create DateTime picker in Strapi with the required field validation but can't save. occurring following error.
apI Parametr
components: []
contentType: {name: "Events", description: "", connection: "default", collectionName: "events",…}
name: "Events"
description: ""
connection: "default"
collectionName: "events"
attributes: {title: {type: "string", required: true},…}
title: {type: "string", required: true}
created_by: {nature: "oneWay", target: "plugins::users-permissions.user", dominant: false, unique: false}
image: {type: "media", multiple: false, required: true}
seo_description: {type: "text"}
seo_title: {type: "string"}
description: {type: "richtext", required: true}
calendly_url: {type: "string"}
start_date: {type: "datetime", required: true}
type: "datetime"
required: true
end_date: {type: "datetime"}
PUT http://localhost:1337/content-type-builder/content-types/application::events.events 400 (Bad Request)```
I am trying to do geo point filter in mongodb in meanjs. i have used mongoosastic modules but i am not able to perform geo point filter.
here below are the mongoose schema and controller code for filter.
Mongoose schema
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
mongoosastic = require('mongoosastic');
var BusinessSchema = new Schema({
name: {type: String, unique: 'Name already exists', trim: true, required: 'Name is required.', es_indexed: true},
searchTags: {type: [String], es_indexed: true},
alias: {type: Array, es_indexed: true},
// geoLocation: { type: [Number], /*/ [<longitude>, <latitude>]*/ index: '2d', /*/ create the geospatial index,*/ required: 'GeoLocation is required.', es_indexed:true,es_type:'geo_point'},
geo_cords: {
type: Array
},
address: {
address1: {type: String, required: 'Address is required', trim: true},
address2: String,
city: {type: String, required: 'City is required', trim: true},
// state: {type: String, required: 'State is required', trim: true},
country: {type: String, required: 'Country is required', trim: true},
postalCode: {type: String, required: 'Postal code is required', trim: true},
neighbourhood: String
},
isActive: {
type: Boolean,
default: true,
es_indexed: true
},
dateUpdated: {
type: Date
, es_indexed: true
},
dateCreated: {
type: Date,
default: Date.now
, es_indexed: true
}
});
controller code for filter and query
var mongoose = require('mongoose'),
Business = mongoose.model('Businesses');
var query = {
"query_string": {
"multi_match": {
"query": categoryIds.join(' OR '),
"fields": ["categoryIds", "relatedCategoryIds"]
}
},
"filter": {
"bool": {
"should": [
{"term": {"address.postalCode": "110016"}},
{"geo_distance": {
"distance": "50km",
"geo_cords": [-122.3050, 37.9174]
}
}
],
}
}
}
Business.search(query, function (err, results) {
// sendResponse(req, res, err, results)
if (!err) {
res.json(results);
} else {
res.status(400).send({message: 'Business Not Found'})
}
});
while doing this i am getting a long error saying
QueryParsingException[[businessess] failed to find geo_point field [geo_cords]
According to the documentation of mongoosastic
Geo mapping
Prior to index any geo mapped data (or calling the synchronize), the mapping must be manualy created with the createMapping (see above).
First, in your schema, define 'geo_cords' this way:
geo_cords: : {
geo_point: {
type: String,
es_type: 'geo_point',
es_lat_lon: true
},
lat: { type: Number },
lon: { type: Number }
}
Add an es_type: 'object' to each Array or embbeded type
alias: {type: Array, es_indexed: true, es_type: 'object'}
Then call .createMapping() on the model just after you've created it.
I have two entities: User and Student. Following is the yaml schema:
ABC\UserBundle\Entity\User:
type: entity
table: abc_user
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
username: { type: string, length: 255, notnull: true, unique: true }
email: { type: string, length: 255, notnull: true, unique: true }
password: { type: string, length: 255, notnull: true }
enabled: { type: boolean }
ABC\UserBundle\Entity\Student:
type: entity
table: abc_student
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
first_name: { type: string, length: 255, notnull: true }
middle_name: { type: string, length: 255 }
last_name: { type: string, length: 255, notnull: true }
OnetoOne:
user:
targetEntity: ABC\UserBundle\Entity\User
My problem is that when I do "doctine:update:schema --dump-sql", user_id field is not added to the Student table and no relationship is created between the entities.
Yaml map is case-sensitive, use the proper name oneToOne for creating relations.
Your are missing the joinColumn option for the OneToOne association:
ABC\UserBundle\Entity\User:
type: entity
table: abc_user
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
username: { type: string, length: 255, notnull: true, unique: true }
email: { type: string, length: 255, notnull: true, unique: true }
password: { type: string, length: 255, notnull: true }
enabled: { type: boolean }
OnetoOne:
student:
targetEntity: ABC\UserBundle\Entity\Student
mappedBy: user
ABC\UserBundle\Entity\Student:
type: entity
table: abc_student
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
first_name: { type: string, length: 255, notnull: true }
middle_name: { type: string, length: 255 }
last_name: { type: string, length: 255, notnull: true }
OnetoOne:
user:
targetEntity: ABC\UserBundle\Entity\User
joinColumn:
name: user_id
referencedColumnName: id