Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 仅索引ElasticSearch映射中的几个字段_Python 3.x_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Indexing_Searchable - Fatal编程技术网 elasticsearch,indexing,searchable,Python 3.x,elasticsearch,Indexing,Searchable" /> elasticsearch,indexing,searchable,Python 3.x,elasticsearch,Indexing,Searchable" />

Python 3.x 仅索引ElasticSearch映射中的几个字段

Python 3.x 仅索引ElasticSearch映射中的几个字段,python-3.x,elasticsearch,indexing,searchable,Python 3.x,elasticsearch,Indexing,Searchable,我正在使用ElasticSearch 6.5。 我已使用以下代码为csv文件编制索引: def create_index(es_object, index_name): created = False # index settings settings = { "settings": { "number_of_shards": 1, "number_of_replicas": 0, "

我正在使用ElasticSearch 6.5。 我已使用以下代码为csv文件编制索引:

def create_index(es_object, index_name):
    created = False
    # index settings
    settings = {
        "settings": {
            "number_of_shards": 1,
            "number_of_replicas": 0,
            "analysis": {
                "filter": {
                    "dbl_metaphone": { 
                        "type":    "phonetic",
                        "encoder": "beider_morse"
                    }
                },
                "analyzer": {
                    "dbl_metaphone": {
                        "tokenizer": "standard",
                        "filter":    "beider_morse"
                    }
                }
            }
        },
        "mappings": {
            "test": {
                #"dynamic": "strict",
                "properties": {
                    "family name": {
                        "type": "text",
                        "index": "analyzed",
                        "fields": {
                            "phonetic": { 
                                "type":     "string",
                                "analyzer": "dbl_metaphone"
                            }
                        }
                    },
                    "Firstname": {
                        "type": "text",
                        "index": "analyzed",
                        "fields": {
                            "phonetic": { 
                                "type":     "string",
                                "analyzer": "dbl_metaphone"
                            }
                        }
                    },

                "Date of birth": {
                    "type": "text",
                    "index": "false"
                },  
                "Place of birth": {
                    "type": "text",
                    "index": "false",
                },

            }
        }
    }
}

    try:
        if not es_object.indices.exists(index_name):
            # Ignore 400 means to ignore "Index Already Exist" error.
            es_object.indices.create(index=index_name, ignore=400, body=settings)
            print('Created Index')
        created = True
    except Exception as ex:
        print(str(ex))
    finally:
        return created
问题是,当我试图用kibana搜索数据时,所有字段都是可搜索和可聚合的。我想把“出生日期”和“出生地”排除在可搜索和可聚合的范围之外

谁能解释一下我的映射有什么问题,以及如何更新索引来实现它


谢谢

让我们用一个简单的例子来尝试一下(通过Kibana中的控制台添加,但您可以很容易地将其更改为普通curl命令):

这对我有用。我可以找到
foo
bar
,但不能找到
baz

此外,刷新索引模式后,出生日期字段既不可搜索也不可聚合:

一些快速观察:

  • 。它位于不同的领域,因此可能与您的问题无关
  • 除非你将来想受苦,否则我会避免字段名中的空格。我可以预见很多事情都会出错

  • 您需要将索引指定为“未分析”

    “出生日期”:{
    “类型”:“文本”,
    “索引”:“未分析”
    
    },

    您真的不希望它们可以搜索吗?那么它有什么用呢?我有一些列是其他列的串联,所以我不想重复搜索。此外,我正在使用kibana ihm,但也使用python api生成基于弹性查询的报告。为了避免太多的结果,因为我使用的是语音和模糊性,所以我必须将搜索限制在某些字段上。最后,报告将包含所有字段!选项index:false exist,但不适用于我,我不知道您为什么要共享正在编制索引的示例文档?
    first\u name;姓氏;出生日期;出生地;概要sam;琼斯;1980-09-09;纽约山姆·琼斯1980-09-09纽约巴黎;希尔顿;1982-01-01;巴黎巴黎希尔顿1980-01-01巴黎詹姆斯;钩1780-05-11;伦敦james Hook 1780-05-11 London
    因此,我只想索引前两列,以使其可搜索,而不是其他列!但是,我希望所有列(即字段)都可以显示在kibanaThanks中。我可以知道你使用的是哪个版本的Kibana和ES吗:)你会怎么处理空白。例如,如果你的名字是约翰·大卫,你会怎么做?这是最新的,6.5.4。字段名中的空格(例如,您有
    “出生日期”
    );在值中它是完全好的。你能看看你的Kibana的管理,检查出生日期字段是否可以搜索和聚合吗?添加到我的答案中
    PUT test
    {
      "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0
      },
      "mappings": {
        "_doc": {
          "dynamic": "strict",
          "properties": {
            "family name": {
              "type": "text",
              "index": "true"
            },
            "Firstname": {
              "type": "text",
              "index": "true"
            },
            "Date of birth": {
              "type": "text",
              "index": "false"
            }
          }
        }
      }
    }
    
    PUT /test/_doc/1
    {
      "family name": "foo",
      "Firstname": "bar",
      "Date of birth": "baz"
    }