Java 段落中的ElasticSearch范围查询
我有一个名为Description的字段,它是一个文本字段,包含如下数据: 这对于3.2之前的版本是好事,但对于3.5及更高版本则是坏事 我想对这种类型的文本运行范围查询。我知道,对于只包含日期/AgeNumbers甚至字符串ID的字段,我们可以使用如下查询Java 段落中的ElasticSearch范围查询,java,
elasticsearch,range,Java,
elasticsearch,Range,我有一个名为Description的字段,它是一个文本字段,包含如下数据: 这对于3.2之前的版本是好事,但对于3.5及更高版本则是坏事 我想对这种类型的文本运行范围查询。我知道,对于只包含日期/AgeNumbers甚至字符串ID的字段,我们可以使用如下查询 { "query": { "range" : { "age" : { "gte" : 10, "lte" : 20,
{
"query": {
"range" : {
"age" : {
"gte" : 10,
"lte" : 20,
"boost" : 2.0
}
}
}
}
但我有一个上面提到的混合字段,我需要对它执行范围查询。此外,我无法更改索引结构。我只能在检索结果后执行查询或进行一些后期处理。那么,有人知道如何运行这种类型的查询,或者甚至在后处理中获得结果后获得我的目标吗?我正在使用Java。我希望我完全理解您在寻找什么 我已经设法创建了一个简单的工作示例 映射 使用字符组标记器: 每当遇到定义集中的字符时,char_组标记器就会将文本分解为术语。在需要简单的自定义标记化,并且模式标记器的使用开销不可接受的情况下,它最有用 张贴一些文件 搜索查询 结果 另一个搜索查询 结果 分析查询 玩下面的查询,直到得到所需的结果 它已经与您的示例兼容 这对于3.2之前的版本是好事,但对于3.5及更高版本则是坏事 希望这有帮助
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "char_group",
"tokenize_on_chars": [
"letter",
"whitespace"
]
}
}
}
},
"mappings": {
"properties": {
"text": {
"type": "text",
"fields": {
"digit": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
}
PUT my_index/_doc/1
{
"text": "This is a good thing for versions before 3.2 but bad for 3.5 and later"
}
PUT my_index/_doc/2
{
"text": "This is a good thing for versions before 5 but bad for 6 and later"
}
GET my_index/_search
{
"query": {
"range": {
"text.digit": {
"gte": 3.2,
"lte": 3.5
}
}
}
}
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"text" : "This is a good thing for versions before 3.2 but bad for 3.5 and later"
}
}
]
}
GET my_index/_search
{
"query": {
"range": {
"text.digit": {
"gt": 3.5
}
}
}
}
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"text" : "This is a good thing for versions before 5 but bad for 6 and later"
}
}
]
}
POST _analyze
{
"tokenizer": {
"type": "char_group",
"tokenize_on_chars": [
"letter",
"whitespace"
]
},
"text": "This is a good thing for versions before 3.2 but bad for 3.5 and later"
}