我正在使用Elasticsearch 5.5,以下是Elasticsearch上的索引
[
{
"_index" : "corpindex-qa",
"_type" : "corpdocs-qa",
"_id" : "5cb468fd35b9db6f2235e4c4",
"_score" : 1.0,
"_source" : {
"Edition" : {
"Values" : {
"title" : "new featured parallex"
}
},
"url" : "/demo-inline-component-capability/demo-of-featured-parallex",
"year" : 2019,
"author" : "",
"docdef" : "new-featured-parallex-reference-1"
}
},
{
"_index" : "corpindex-qa",
"_type" : "corpdocs-qa",
"_id" : "5ccfe1dd6948151485158661",
"_score" : 1.0,
"_source" : {
"Edition" : {
"Values" : {
"title" : "demo of event careers",
"description" : "careers"
}
},
"url" : "/demo-inline-component-capability/demo-of-event-card",
"year" : 2019,
"author" : "",
"docdef" : "inline-event-card"
}
}]
尝试通过在带有Elasticsearch客户端模块的nodejs上使用带有条件的查询来获取文档。
client.search({
index: searchIndex,
type: searchType
, body: {
query: {
terms: {
"url": ["/demo-inline-component-capability/demo-of-featured-parallex","/demo-inline-component-capability/demo-of-event-card"]
}
}
}
});
在执行上述操作时获取零文档。
{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
以下是贴图的详细信息,该内容取自elasticsaerch
{
corpindex-qa: {
aliases: { },
mappings: {
corpdocs-qa: {
properties: {
url: {
type: "text",
fields: {
keyword: {
type: "keyword",
ignore_above: 256
}
}
},
year: {
type: "long"
}
}
}
},
settings: {
index: {
creation_date: "1559900006341",
number_of_shards: "5",
number_of_replicas: "1",
uuid: "xL6PICFARZq6zMZBpm-75A",
version: {
created: "5050399"
},
provided_name: "corpindex-qa"
}
}
}
}
请分享对我有帮助的想法。
答案 0 :(得分:1)
由于您要匹配精确的url
,因此请使用url.keyword
而不是url
。将您的查询更新如下:
client.search({
index: searchIndex,
type: searchType
, body: {
query: {
terms: {
"url.keyword": ["/demo-inline-component-capability/demo-of-featured-parallex","/demo-inline-component-capability/demo-of-event-card"]
}
}
}
});