elasticsearch 限制elasticsearch响应中的列文本长度,elasticsearch,search,substring,elasticsearch,Search,Substring" /> elasticsearch 限制elasticsearch响应中的列文本长度,elasticsearch,search,substring,elasticsearch,Search,Substring" />

elasticsearch 限制elasticsearch响应中的列文本长度

elasticsearch 限制elasticsearch响应中的列文本长度,elasticsearch,search,substring,elasticsearch,Search,Substring,下面是我的elasticsearch映射 { "metadata" : { "mappings" : { "properties": { "id": {"type":"keyword"}, "title": {"type":"keyword"}, "created": {"type":"date"}, "modified": {"type":"date"}, "keyword": {"type

下面是我的elasticsearch映射

{
  "metadata" : {
    "mappings" : {
      "properties": {
        "id": {"type":"keyword"},
        "title": {"type":"keyword"},
        "created": {"type":"date"},
        "modified": {"type":"date"},
        "keyword": {"type":"keyword"},
        "description": {"type":"text"}
      }
    }
  }
}
这是我的ES查询,可根据用户对多个字段的查询检索数据,最多可点击5次,按修改日期排序,仅显示标题和说明字段。这个查询正如我所期望的那样完美地工作

GET /_search
{
    "query": {
        "multi_match" : {
            "query" : "UK House Price Index",
            "fields" : ["title", "keyword", "description"]
        }
    },
    "size": 5,
    "_source": ["title", "description"],
    "sort": {"modified": "asc"}
}
我想将我的描述字段响应限制为最多100个字符。我是ES新手。有人能告诉我如何有效地完成这项工作吗?

您可以使用它来获取匹配的
说明的相关部分。它有
fragment\u size
设置,本质上就是您所追求的字符串连接,有趣的是,默认值为100

POST long_desc/_doc
{"title":"UK House Price Index","keyword":"UK House Price Index","description":"APM automatically collects in-depth performance metrics and errors from inside your applications. Ingest logs UK House Price Index from popular data sources and easily visualize in preconfigured dashboards."}
屈服

[
  {
    "_index":"long_desc",
    "_type":"_doc",
    "_id":"zSWAwnEBPAbzy1R_Uk-I",
    "_score":null,
    "_source":{
      "title":"UK House Price Index"
    },
    "highlight":{
      "description":[
        "Ingest logs UK House Price Index from popular data sources and easily visualize in preconfigured dashboards"
      ]
    }
    ...
  }
]
仅供参考
pre_u
post_u标签
默认设置为
,因此您的前端实际上不需要进行任何后期处理来突出显示匹配项。我选择了空字符串来保持
描述
干净。

您可以使用它来获取匹配的
描述
的相关部分。它有
fragment\u size
设置,本质上就是您所追求的字符串连接,有趣的是,默认值为100

POST long_desc/_doc
{"title":"UK House Price Index","keyword":"UK House Price Index","description":"APM automatically collects in-depth performance metrics and errors from inside your applications. Ingest logs UK House Price Index from popular data sources and easily visualize in preconfigured dashboards."}
屈服

[
  {
    "_index":"long_desc",
    "_type":"_doc",
    "_id":"zSWAwnEBPAbzy1R_Uk-I",
    "_score":null,
    "_source":{
      "title":"UK House Price Index"
    },
    "highlight":{
      "description":[
        "Ingest logs UK House Price Index from popular data sources and easily visualize in preconfigured dashboards"
      ]
    }
    ...
  }
]

仅供参考
pre_u
post_u标签
默认设置为
,因此您的前端实际上不需要进行任何后期处理来突出显示匹配项。我选择空字符串来保持
描述
干净。

这不是在前端很容易做到的事情吗?当然。但我们的一些描述是相当长的例子发表的论文。所以我认为在我的案例中,在后端ES服务中这样做会更有效率哦,我明白了。那么让我写一个答案。这不是很容易在前端完成的事情吗?当然。但我们的一些描述是相当长的例子发表的论文。所以我认为在我的案例中,在后端ES服务中这样做会更有效率哦,我明白了。让我写一个答案。