Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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 仅在混合字段中搜索数字(elasticsearch)_Python_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nosql - Fatal编程技术网 elasticsearch,nosql,Python,elasticsearch,Nosql" /> elasticsearch,nosql,Python,elasticsearch,Nosql" />

Python 仅在混合字段中搜索数字(elasticsearch)

Python 仅在混合字段中搜索数字(elasticsearch),python,elasticsearch,nosql,Python,elasticsearch,Nosql,我有一个带有电话号码的字段,其格式为XXX-XXX-XXXX或XXXXXXXXX,这是一个合并表 我希望能够搜索XXXXXXXXX,并从这两种格式的结果 我试着用十进制数字过滤器,但没用。 以下是我尝试过的设置,如下所示: mapping = { 'mappings': { DOC_TYPE: { 'properties': { 'first_name': { 'type':

我有一个带有电话号码的字段,其格式为XXX-XXX-XXXX或XXXXXXXXX,这是一个合并表

我希望能够搜索XXXXXXXXX,并从这两种格式的结果

我试着用十进制数字过滤器,但没用。 以下是我尝试过的设置,如下所示:

mapping = {
    'mappings': {
        DOC_TYPE: {
            'properties': {
                'first_name': {
                    'type': 'text',
                    'analyzer': 'word_splitter'
                },
                'last_name': {
                    'type': 'text',
                    'analyzer': 'word_splitter'
                },
                'email': {
                    'type': 'text',
                    'analyzer': 'email'
                },
                'gender': {
                    'type': 'text'
                },
                'ip_address': {
                    'type': 'text'
                },
                'language': {
                    'type': 'text'
                },
                'phone': {
                    'type': 'text',
                    'analyzer': 'digits'
                },
                'id': {
                    'type': 'long'
                }

            }
        }
    },
    'settings': {
        'analysis': {
            'analyzer': {
                'my_analyzer': {
                    'type': 'whitespace'
                },
                'better': {
                    'type': 'standard'
                },
                'word_splitter': {
                    'type': 'custom',
                    'tokenizer': 'nGram',
                    'min_gram': 5,
                    'max_gram': 5,
                    'filter': [
                        'lowercase'
                    ]
                },
                'email': {
                    'type': 'custom',
                    'tokenizer': 'uax_url_email'
                },
                'digits': {
                    'type': 'custom',
                    'tokenizer': 'whitespace',
                    'filter': [
                        'decimal_digit'
                    ]
                }
            }
        }
    }
}
有什么想法吗

在编制索引之前,请使用删除连字符。举个简单的例子:

设置自定义分析器并将其应用于电话字段

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "phone_analyzer": {
          "tokenizer": "standard",
          "char_filter": [
            "phone_char_filter"
          ]
        }
      },
      "char_filter": {
        "phone_char_filter": {
          "type": "mapping",
          "mappings": [
            "- => "
          ]
        }
      }
    }
  },
  "mappings": {
    "_doc": {
      "properties": {
        "phone": { 
          "type": "text",
          "analyzer": "phone_analyzer"
        }
      }
    }
  }
}
添加一些文档

POST my_index/_doc
{"phone": "123-456-7890"}

POST my_index/_doc
{"phone": "2345678901"}
以xxx xxx xxxx格式搜索

GET my_index/_search
{
  "query": {
    "match": {
      "phone": "123-456-7890"
    }
  }
}
GET my_index/_search
{
  "query": {
    "match": {
      "phone": "1234567890"
    }
  }
}
以XXXXXXXXX格式搜索

GET my_index/_search
{
  "query": {
    "match": {
      "phone": "123-456-7890"
    }
  }
}
GET my_index/_search
{
  "query": {
    "match": {
      "phone": "1234567890"
    }
  }
}

到目前为止你试过什么?你能发布你的代码吗?我是elasticsearch的新手,因此如果您对设置有任何意见,请随时联系。