简体   繁体   English

Elasticsearch查询

[英]Elasticsearch Query

I need some help to query a field in my index. 我需要一些帮助来查询索引中的字段。 This field will have data such as: 该字段将包含以下数据:

GB10 GB10
GB40 GB40
GB45 GB45
UK09 UK09
UK40 英国40

If I have the query: 如果我有查询:

"Show me the code GB 40"

( note the space between GB and 40 ) 请注意GB和40之间的空格

I would like the JSON to return the result for the GB40 as the top result. 我希望JSON返回GB40的结果作为最佳结果。 Can anyone help with how I can I go about doing this and any changes I might need to make? 任何人都可以帮助我进行此操作以及可能需要进行的任何更改吗? I haven't set the field as analysed yet. 我还没有设置分析领域。

Ok, if you have words with such pattern then you might want to exploit split on letter-number transitions: "SD500" → "SD", "500" using word_delimiter tokenizer filter in elastic. 好的,如果您有带有这种模式的单词,则可能需要在弹性数字中使用word_delimiter标记器过滤器来利用split on letter-number transitions: "SD500" → "SD", "500"

You can split the word on letter-word transition using this filter to have both letter and number part of the word stored seperately on inverted index. 您可以使用此过滤器在字母-单词转换中拆分单词,以将单词的字母和数字部分分别存储在倒排索引中。 Neverthless this will also keep a copy of exact value on index. 但是,这也会在索引上保留准确值的副本。

Please refer the mappings and queries below 请参考下面的映射和查询

PUT testindex_48
{
    "settings": {
        "analysis": {
            "analyzer": {

                "word_delimiter_analyzer": {
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "word_delimiter"
                    ],
                    "ignore_case": true,
                    "preserve_original": true
                }
            },
             "filter":{

            "word_delimiter":{
              "type":"word_delimiter",
              "generate_word_parts":true,
              "preserve_original": true
            }
        }
        }
    },
    "mappings": {
        "table1": {
            "properties": {
                "title": {
                    "type": "string",
                    "analyzer": "word_delimiter_analyzer"
                }
            }
        }
    }
}

POST testindex_48/table1
{
  "title" : "EC450"
}

POST testindex_48/table1/_search
{
  "query": {"bool": {"must": [
    {"term": {
      "title": {
        "value": "450"
      }
    }}
  ]}}
}

POST testindex_48/table1/_search
{
  "query": {"bool": {"must": [
    {"term": {
      "title": {
        "value": "ec"
      }
    }}
  ]}}
}


POST testindex_48/table1/_search
{
  "query": {"bool": {"must": [
    {"term": {
      "title": {
        "value": "ec450"
      }
    }}
  ]}}
}

Now your usecase if user enters "EC 450", you can build a similar query like the follows. 现在您的用例是,如果用户输入“ EC 450”,则可以构建类似如下的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM