我曾经在仅使用 JavaScript 来使用 Jest 时解决了类似的错误,但目前我无法使用 Typescript 来解决类似的错误。
我的所有测试都运行良好,直到我安装了需要@types/jest-environment-puppeteer,@types/puppeteer和的 Puppeteer @types/expect-puppeteer。
安装它们后,puppeteer 测试运行完美,但其他测试开始失败并出现以下错误。
D:\...\api\node_modules\uuid\dist\esm-browser\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';
^^^^^^
SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (../node_modules/jest-runtime/build/index.js:1796:14)
at Object.require (../node_modules/@nestjs/common/decorators/core/injectable.decorator.js:4:16)
Run Code Online (Sandbox Code Playgroud)
我做了什么?
allowJs: true打开tsconfig.json并设置transformIgnorePatternson jest 配置。这样笑话就可以从node_modules/
之后编译文件,此错误停止但测试因另一个奇怪的原因失败。更糟糕的是,测试开始时间增加太多。
所以我保留了allowJs原始设置并更新了笑话配置
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
Run Code Online (Sandbox Code Playgroud)
到
"transform": {
"^.+\\.(t)s$": "ts-jest"
}
Run Code Online (Sandbox Code Playgroud)
所以目前 ts-jest 不编译 js 文件。但我认为我无法让 babel 选择js文件的转换。这些是我的笑话配置:
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": …Run Code Online (Sandbox Code Playgroud) 我有一套像
{
tags:['a','b','c']
// ... a bunch properties
}
Run Code Online (Sandbox Code Playgroud)
如标题所述:有没有办法使用Nest过滤包含任何给定标签的所有文档?
例如,上面的记录将匹配['c','d']
或者我应该手动构建多个"OR"?
是否可以从NEST客户端获取原始搜索查询?
var result = client.Search<SomeType>(s => s
.AllIndices()
.Type("SomeIndex")
.Query(query => query
.Bool(boolQuery => BooleanQuery(searchRequest, mustMatchQueries)))
);
Run Code Online (Sandbox Code Playgroud)
我真的很想调试为什么我会得到一定的结果.
我正在尝试更新现有的索引文档.我有索引标签,标题和所有者字段.现在,当用户更改标题时,我需要查找并更新索引中的文档.
我应该更新和替换整个文档还是只更改标题字段?
public void UpdateDoc(ElasticsearchDocument doc)
{
Uri localhost = new Uri("http://localhost:9200");
var setting = new ConnectionSettings(localhost);
setting.SetDefaultIndex("movies");
var client = new ElasticClient(setting);
IUpdateResponse resp = client.Update<ElasticsearchDocument, IndexedDocument>(
d => d.Index("movies")
.Type(doc.Type)
.Id(doc.Id), doc);
}
Run Code Online (Sandbox Code Playgroud)
它只是不起作用.上面的代码生成语法错误.有没有人知道使用ElasticSearch的C#NEST客户端执行此操作的正确方法?
情况:
ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'logIn')
TypeError: Cannot read properties of undefined (reading 'logIn')
at authenticate (/home/gleb/Projects/artwine-api/node_modules/passport/lib/middleware/authenticate.js:96:21)
at /home/gleb/Projects/artwine-api/node_modules/@nestjs/passport/dist/auth.guard.js:91:3
at new Promise (<anonymous>)
at /home/gleb/Projects/artwine-api/node_modules/@nestjs/passport/dist/auth.guard.js:83:83
at JWTAccessAuthGuard.<anonymous> (/home/gleb/Projects/artwine-api/node_modules/@nestjs/passport/dist/auth.guard.js:49:36)
at Generator.next (<anonymous>)
at fulfilled (/home/gleb/Projects/artwine-api/node_modules/@nestjs/passport/dist/auth.guard.js:17:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Run Code Online (Sandbox Code Playgroud)
捕获错误的护照库函数的代码:
return function authenticate(req, res, next) {
req.login =
req.logIn = req.logIn || IncomingMessageExt.logIn;
req.logout =
req.logOut = req.logOut || IncomingMessageExt.logOut;
req.isAuthenticated …Run Code Online (Sandbox Code Playgroud) 我创建了下面的对象,它将映射到ElasticSearch类型.我想将该UnivId属性排除在索引之外:
[ElasticType(Name = "Type1")]
public class Type1
{
// To be ignored
public string UnivId { get; set; }
[ElasticProperty(Name="Id")]
public int Id { get; set; }
[ElasticProperty(Name = "descSearch")]
public string descSearch { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我正在使用ElasticSearch和我的C#项目中的NEST一起玩.我的用例包括几个具有不同文档类型的索引,到目前为止我分别查询.现在我想实现一个全局搜索功能,它可以查询所有现有索引,文档类型并正确评分结果.
所以我的问题是:如何通过使用NEST实现这一目标?
目前我正在使用该功能,SetDefaultIndex但如何定义多个索引?
也许为了更好地理解,这是我想用NEST实现的查询:
{
"query": {
"indices": {
"indices": [
"INDEX_A",
"INDEX_B"
],
"query": {
"term": {
"FIELD": "VALUE"
}
},
"no_match_query": {
"term": {
"FIELD": "VALUE"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
TIA
我无法弄清楚为什么我的搜索区分大小写.我读过的所有内容都说ES默认情况下不敏感.我有指定标准分析器用于索引和搜索的映射,但似乎有些东西仍然区分大小写 - 即,通配符:
"query": {
"bool": {
"must": [
{
"wildcard": {
"name": {
"value": "Rae*"
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
这失败但是"rae*"按预期工作.我需要使用通配符进行'开始'类型搜索(我推测).
我正在使用.Net应用程序中的NEST,并在创建索引时指定分析器:
var settings = new IndexSettings();
settings.NumberOfReplicas = _configuration.Replicas;
settings.NumberOfShards = _configuration.Shards;
settings.Add("index.refresh_interval", "10s");
settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("keyword", new KeywordAnalyzer()));
settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("simple", new SimpleAnalyzer()));
Run Code Online (Sandbox Code Playgroud)
在这种情况下,它使用简单的分析仪,但标准的分析仪具有相同的结果.
映射看起来像这样:
name: {
type: string
analyzer: simple
store: yes
}
Run Code Online (Sandbox Code Playgroud)
有人在这里有任何想法吗?
谢谢
我正在使用NEST库与ElasticSearch进行交互,我正试图找出一种基于非类型数据构建索引类型/嵌套对象的方法.该类型具有以下基本结构.
public class Entity : DynamicObject
{
public string Id { get; set; }
// a bunch of other simple properties
public override IEnumerable<string> GetDynamicMemberNames()
{
return Data.Select(x => x.Name);
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
var dictionary = Data.First(x => x.Name == binder.Name);
result = dictionary;
return true;
}
// each instance of one these should be a nested object type
public IList<NestedType> Data { get; set; }
public class NestedType
{
// How do …Run Code Online (Sandbox Code Playgroud) 默认情况下,NEST会在将对象发送到Elasticsearch进行索引时使用驼峰大小写对象和属性名称.如何在NEST中为Elasticsearch文档禁用骆驼套管字段名称?我做了大量的研究,并且有关于这个主题的邮件列表主题,但它似乎已经过时,因为一些方法已被重命名或不再存在.
IConnectionPool connectionPool = new SniffingConnectionPool(m_ElasticsearchNodeUris);
ConnectionSettings settings = new ConnectionSettings(connectionPool);
settings.SetDefaultTypeNameInferrer(p => p.Name); //This disables camel casing for object type names
ElasticClient client = new ElasticClient(settings);
Run Code Online (Sandbox Code Playgroud)
邮件列表中的信息表明应添加此代码以处理字段名称,但客户端方法似乎不存在:
client.ModifyJsonSerializationSettings(s => s.ContractResolver = new Nest.Resolvers.ElasticResolver(settings);
Run Code Online (Sandbox Code Playgroud)
有没有人有任何更新的语法来处理这个?谢谢.