带有值数组的Elasticsearch查询

时间:2019-06-11 15:46:08

标签: node.js elasticsearch

我正在使用Elasticsearch 5.5,我可以通过使用nodejs elasticsearch客户端模块来获取文档。

这是我用来从elasticsearch获取结果的代码段

 client.search({
                        index: searchIndex,
                        type: searchType
                        , body: {
                            query: {
                                terms: {
                                    "url": ["/demo-inline-component-capability/demo-of-video-playlist","/demo-inline-component-capability/demo-of-featured-parallex","/demo-inline-component-capability/demo-of-ref-event-card","/demo-inline-component-capability/demo-of-event-card"]
                                }
                            }
                        }
                    });

这是Elasticsearch的结果详细信息

[
{
"_index":"corpindex-qa",
"_type":"corpdocs-qa",
"_id":"5cb468fd35b9db6f2235e4c4",
"_score":0.6931472,
"_source":{
"Edition":{
"Values":{
"title":"new featured parallex",
"indexContent":" new featured "
}
},
"url":"/demo-inline-component-capability/demo-of-featured-parallex"
},
"isPromoted":true
},
{
"_index":"corpindex-qa",
"_type":"corpdocs-qa",
"_id":"5ccfe1dd6948151485158661",
"_score":0.6931472,
"_source":{
"Edition":{
"Values":{
"title":"demo of event careers",
"description":"careers",
"indexContent":" careers "
}
},
"url":"/demo-inline-component-capability/demo-of-event-card"
},
"isPromoted":true
},
{
"_index":"corpindex-qa",
"_type":"corpdocs-qa",
"_id":"5cd0203cf5490e157ba5a196",
"_score":0.6931472,
"_source":{
"Edition":{
"Values":{
"title":"reference event cards",
"indexContent":" reference"
}
},
"url":"/demo-inline-component-capability/demo-of-ref-event-card"
},
"isPromoted":true
},
{
"_index":"corpindex-qa",
"_type":"corpdocs-qa",
"_id":"5cb460b0a203f36ee4f7c372",
"_score":0.2876821,
"_source":{
"Edition":{
"Values":{
"title":"demo of video playlists",
"indexContent":" demo "
}
},
"url":"/demo-inline-component-capability/demo-of-video-playlist"
},
"isPromoted":true
},
{
"_index":"corpindex-qa",
"_type":"corpdocs-qa",
"_id":"5cb44d90c11bb16ded816ebe",
"_score":null,
"_source":{
"Edition":{
"Values":{
"title":"demo of data point set careers",
"description":"careers",
"indexContent":" careers "
}
},
"url":"/demo-inline-component-capability/demo-of-data-point-set"
},
"sort":[
1555320208440
]
},
{
"_index":"corpindex-qa",
"_type":"corpdocs-qa",
"_id":"5c73d0a28c2b9817bc51cbcd",
"_score":null,
"_source":{
"Edition":{
"Values":{
"title":"Xfinity TV’sa Lunar New Year collection is a celebration of the vast contributions the Asian American community makes to entertainment across comcast careers",
"description":"mobile name",
"indexContent":" mobile"
}
},
"url":"/lunar-festival"
},
"sort":[
1551093922066
]
}
]

,但问题是混淆结果(顺序不对)。我需要一个按URL顺序排列的结果,我以前用URL数组进行查询。

["/demo-inline-component-capability/demo-of-video-playlist","/demo-inline-component-capability/demo-of-featured-parallex","/demo-inline-component-capability/demo-of-ref-event-card","/demo-inline-component-capability/demo-of-event-card"]

以下是贴图的详细信息,该内容取自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 个答案:

没有答案