弹性搜索排序错误-Search_phase_execution_exception

发布于 2025-02-01 04:29:49 字数 1885 浏览 2 评论 0原文

我面临着在弹性搜索查询中对值进行排序值的问题。我正在使用Sort进行简单的搜索,但会遇到以下错误。该查询无需排序参数。

弹性搜索客户端版本:版本7.6.1 (使用此版本,因为我正在使用OpenSearch)

search_phase_execution_exception:[illegal_argument_exception]原因: 文本字段未针对需要每件文档的操作进行优化 诸如聚合和分类之类的现场数据,因此这些操作是 默认情况下禁用。请改用关键字字段。 或者,在[subtype]上设置fieldData = true以加载字段 通过撤消倒置索引来数据。请注意,这可以使用 大量内存。

代码示例:

const {Client} = require('@elastic/elasticsearch') // Version 7.6.1
var connectionString = 'https://admin:admin@localhost:9200'
const client = new Client({
    node: connectionString,
    ssl: {
        rejectUnauthorized: false
    }
})
client.info()
    .then(async response => {
        console.log('success', response.statusCode)
        var query = {
            "query": {
                "match": {
                    "revhostname": {
                        "query": "ten.tsacmoc.ac.1dsh.631-651-14-37-c",
                    },
                },
            },
            "sort": [
                {
                    "revhostname": {"order": "asc"},
                    "subtype": {"order": "asc"},
                    "value": {"order": "asc"},
                }
            ],
        };
        var response = await client.search({
            index: 'r7',
            body: query,
        });
        console.log("Search results:", JSON.stringify(response));
    })
    .catch(error => {
        console.error('error', JSON.stringify(error))
    })

映射:

{
     "properties": {
       "revhostname": {
         "type" : "keyword"
       },
       "value": {
         "type" : "keyword"
       },
       "subtype": {
         "type" : "keyword"
       },
       "timestamp": {
         "type" : "long"
       },
       "ip": {
         "type" : "ip"
       }
     }
   }

我尝试在映射中添加fieldData = true,但问题没有解决。感谢您的帮助。

谢谢。

I am facing an issue with sorting values in an elastic search query. I am doing a simple search with sort but getting the following error. The query works without a sort parameter.

Elastic search client version: Version 7.6.1(Using this version because I am using opensearch)

search_phase_execution_exception: [illegal_argument_exception] Reason:
Text fields are not optimised for operations that require per-document
field data like aggregations and sorting, so these operations are
disabled by default. Please use a keyword field instead.
Alternatively, set fielddata=true on [subtype] in order to load field
data by uninverting the inverted index. Note that this can use
significant memory.

Code Sample:

const {Client} = require('@elastic/elasticsearch') // Version 7.6.1
var connectionString = 'https://admin:admin@localhost:9200'
const client = new Client({
    node: connectionString,
    ssl: {
        rejectUnauthorized: false
    }
})
client.info()
    .then(async response => {
        console.log('success', response.statusCode)
        var query = {
            "query": {
                "match": {
                    "revhostname": {
                        "query": "ten.tsacmoc.ac.1dsh.631-651-14-37-c",
                    },
                },
            },
            "sort": [
                {
                    "revhostname": {"order": "asc"},
                    "subtype": {"order": "asc"},
                    "value": {"order": "asc"},
                }
            ],
        };
        var response = await client.search({
            index: 'r7',
            body: query,
        });
        console.log("Search results:", JSON.stringify(response));
    })
    .catch(error => {
        console.error('error', JSON.stringify(error))
    })

Mapping:

{
     "properties": {
       "revhostname": {
         "type" : "keyword"
       },
       "value": {
         "type" : "keyword"
       },
       "subtype": {
         "type" : "keyword"
       },
       "timestamp": {
         "type" : "long"
       },
       "ip": {
         "type" : "ip"
       }
     }
   }

I tried adding fielddata=true in mapping but the issue was not solved. Your help is much appreciated.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷血 2025-02-08 04:29:49

正如您在注释中提到的映射时,您的RevHostName字段定义为text关键字字段类型和Elasticsearch类型不允许在文本字段类型。

如果您的映射仍然与您在评论中提到的相同,则需要使用字段名称,例如revhostname.keyword将解决问题。

const {Client} = require('@elastic/elasticsearch') // Version 7.6.1
var connectionString = 'https://admin:admin@localhost:9200'
const client = new Client({
    node: connectionString,
    ssl: {
        rejectUnauthorized: false
    }
})
client.info()
    .then(async response => {
        console.log('success', response.statusCode)
        var query = {
            "query": {
                "match": {
                    "revhostname": {
                        "query": "ten.tsacmoc.ac.1dsh.631-651-14-37-c",
                    },
                },
            },
            "sort": [
                {
                    "revhostname.keyword": {"order": "asc"},
                    "subtype.keyword": {"order": "asc"},
                    "value.keyword": {"order": "asc"},
                }
            ],
        };
        var response = await client.search({
            index: 'r7',
            body: query,
        });
        console.log("Search results:", JSON.stringify(response));
    })
    .catch(error => {
        console.error('error', JSON.stringify(error))
    })

As you mentioned mapping in a comment, your revhostname field is defined as text and keyword both type of field and Elasticsearch dont allow sorting on text type of field.

If your mapping is still same as you mentioned in comment then you need to use the field name like revhostname.keyword which will resolved issue.

const {Client} = require('@elastic/elasticsearch') // Version 7.6.1
var connectionString = 'https://admin:admin@localhost:9200'
const client = new Client({
    node: connectionString,
    ssl: {
        rejectUnauthorized: false
    }
})
client.info()
    .then(async response => {
        console.log('success', response.statusCode)
        var query = {
            "query": {
                "match": {
                    "revhostname": {
                        "query": "ten.tsacmoc.ac.1dsh.631-651-14-37-c",
                    },
                },
            },
            "sort": [
                {
                    "revhostname.keyword": {"order": "asc"},
                    "subtype.keyword": {"order": "asc"},
                    "value.keyword": {"order": "asc"},
                }
            ],
        };
        var response = await client.search({
            index: 'r7',
            body: query,
        });
        console.log("Search results:", JSON.stringify(response));
    })
    .catch(error => {
        console.error('error', JSON.stringify(error))
    })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文