gpt4 book ai didi

python - Elasticsearch 未显示字段

转载 作者:行者123 更新时间:2023-12-03 02:00:52 25 4
gpt4 key购买 nike

我是 Elasticsearch 的新手。我正在尝试为我的一个大学项目用Python实现它。我想将Elastic搜索用作简历索引器。除了显示_source field中的所有字段外,其他所有东西都工作正常。我不需要某些字段,我尝试了太多事情,但没有任何效果。下面是我的代码

es = Elastcisearch()
query = {
"_source":{
"exclude":["resume_content"]
},
"query":{
"match":{
"resume_content":{
"query":keyword,
"fuzziness":"Auto",
"operator":"and",
"store":"false"
}
}
}
}

res = es.search(size=es_conf["MAX_SEARCH_RESULTS_LIMIT"],index=es_conf["ELASTIC_INDEX_NAME"], body=query)

返回资源

其中 es_conf是我的本地词典。

除了以上代码,我还尝试了 _source:false_source:[name of my fields]fields:[name of my fields]。我也在搜索方法中尝试了 store=False。有任何想法吗?

最佳答案

您是否尝试仅使用fields

这是一个简单的例子。我建立了一个映射,包含三个字段,(想象中的)名为"field1""field2""field3":

PUT /test_index
{
"mappings": {
"doc": {
"properties": {
"field1": {
"type": "string"
},
"field2": {
"type": "string"
},
"field3": {
"type": "string"
}
}
}
}
}

然后我索引了三个文档:
POST /test_index/doc/_bulk
{"index":{"_id":1}}
{"field1":"text11","field2":"text12","field3":"text13"}
{"index":{"_id":2}}
{"field1":"text21","field2":"text22","field3":"text23"}
{"index":{"_id":3}}
{"field1":"text31","field2":"text32","field3":"text33"}

假设我想在 "text22"字段中找到包含 "field2"的文档,但是我只想返回 "field1"和“ field2”的内容。这是查询:
POST /test_index/doc/_search
{
"fields": [
"field1", "field2"
],
"query": {
"match": {
"field2": "text22"
}
}
}

返回:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.4054651,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "2",
"_score": 1.4054651,
"fields": {
"field1": [
"text21"
],
"field2": [
"text22"
]
}
}
]
}
}

这是我使用的代码: http://sense.qbox.io/gist/69dabcf9f6e14fb1961ec9f761645c92aa8e528b

使用Python适配器进行设置应该很简单。

关于python - Elasticsearch 未显示字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com