代码之家  ›  专栏  ›  技术社区  ›  blackstar012

弹性搜索uri调用返回一个字段

  •  0
  • blackstar012  · 技术社区  · 7 年前

    我在我的项目中使用弹性搜索。由于许多原因,我不得不通过URI调用Elastic。例如: http://localhost:9200//demo/localetranslatemodel/_search?default_operator=AND&q=localeId%3Adaefa52a-cada-4370-9ae5-6bcfb50a9cf8+name%3AlblCommon_PartCost "

    这份申报表:

    {
    
        "took": 3,
        "timed_out": false,
        "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 8.272978,
        "hits": [
            {
                "_index": "demo",
                "_type": "localetranslatemodel",
                "_id": "31bb0b3f-ace5-4007-b619-009f3e76bafc",
                "_score": 8.272978,
                "_source": {
                    "translate": "Part cost",
                    "localeId": "daefa52a-cada-4370-9ae5-6bcfb50a9cf8",
                    "name": "lblCommon_PartCost",
                    "id": "31bb0b3f-ace5-4007-b619-009f3e76bafc"
                }
            }
        ]
    }
    }
    

    所以我的问题是:我可以只返回“翻译:“部分成本”吗?或者,对我来说更好的是,只返回“部分成本”? 我使用HttpClient在ASP中调用Api。NET项目。 非常感谢你提供了有用的答案,我正在努力做一周

    如果我问一些不可能的问题,所有的解决方案都对我有好处。(如仅返回_源)

    1 回复  |  直到 7 年前
        1
  •  0
  •   dadoonet    7 年前

    是 啊响应过滤可以做到这一点。

    阅读: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/common-options.html#common-options-response-filtering

    此外,您还可以请求特定字段,而不是获取完整的源字段。取决于你真正需要什么。看见 https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-source-filtering.html