首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带空格的弹性搜索排序

带空格的弹性搜索排序
EN

Stack Overflow用户
提问于 2014-03-21 07:42:39
回答 1查看 1.2K关注 0票数 3

我有弹性搜索索引,名称为,清除,类型为它包含名为title的字段。我使用river插件创建了这个索引/类型。我使用以下api更改了标题字段的映射。

代码语言:javascript
复制
 PUT clear/positionTemplate/_mapping
{
    "mappings": {
        "positionTemplate": {
            "properties": {
                "title": {
                    "type": "string", 
                    "index": "not_analyzed"
                }
            }
        }
    }
}

提交的标题包含以下值:

"Java开发人员“

"C开发者“

"Ruby开发人员“

"Java QA“

"Ruby QA“

"Java开发“

运行以下查询时,排序不正确。

代码语言:javascript
复制
{
  "sort" : [{
    "title" : {"order":"desc"}
  }], 
  "fields" : [ "title"]
}

产出如下:

代码语言:javascript
复制
{
    "_shards": {
        "failed": 0,
        "successful": 5,
        "total": 5
    },
    "hits": {
        "hits": [
            {
                "_id": "3",
                "_index": "clear",
                "_score": null,
                "_type": "positionTemplate",
                "fields": {
                    "title": [
                        "Ruby Developer"
                    ]
                },
                "sort": [
                    "ruby"
                ]
            },
            {
                "_id": "5",
                "_index": "clear",
                "_score": null,
                "_type": "positionTemplate",
                "fields": {
                    "title": [
                        "Ruby QA"
                    ]
                },
                "sort": [
                    "ruby"
                ]
            },
            {
                "_id": "4",
                "_index": "clear",
                "_score": null,
                "_type": "positionTemplate",
                "fields": {
                    "title": [
                        "Java QA"
                    ]
                },
                "sort": [
                    "qa"
                ]
            },
            {
                "_id": "15",
                "_index": "clear",
                "_score": null,
                "_type": "positionTemplate",
                "fields": {
                    "title": [
                        "Java Dev"
                    ]
                },
                "sort": [
                    "java"
                ]
            },
            {
                "_id": "1",
                "_index": "clear",
                "_score": null,
                "_type": "positionTemplate",
                "fields": {
                    "title": [
                        "Java Developer"
                    ]
                },
                "sort": [
                    "java"
                ]
            },
            {
                "_id": "2",
                "_index": "clear",
                "_score": null,
                "_type": "positionTemplate",
                "fields": {
                    "title": [
                        "C Developer"
                    ]
                },
                "sort": [
                    "developer"
                ]
            }
        ],
        "max_score": null,
        "total": 6
    },
    "timed_out": false,
    "took": 2
}

这是错误的。有人能指点我怎么改正吗?

EN

回答 1

Stack Overflow用户

发布于 2020-07-30 14:51:07

您需要重新映射字段。

示例:

代码语言:javascript
复制
{
  "<field name>": {
    "type" "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  }
}

然后,在排序方面,您需要指定“关键字”。

示例:

代码语言:javascript
复制
GET <index>/_search
{
  "sort": [
  {
    "<field name>.keyword": {
      "order": "asc"
    }
  }
 ]
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22552973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档