Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.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
Java Elasticsearch:按值排序和动态模板_Java_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Java,elasticsearch" /> elasticsearch,Java,elasticsearch" />

Java Elasticsearch:按值排序和动态模板

Java Elasticsearch:按值排序和动态模板,java,elasticsearch,Java,elasticsearch,我需要对以下文件进行排序: { customer: { fullname: "Lorem ipsum" }, order_number: "12313131", company: { name: "Test Inc." }, date: "10.06.2015 18:00" } 但就我所知,我无法按分析字段中的值进行排序。在这里,我尝试创建一个映射: { "mappings": { "_default_": {

我需要对以下文件进行排序:

{
  customer: {
    fullname: "Lorem ipsum"
  },
  order_number: "12313131",
  company: {
    name: "Test Inc."
  },
  date: "10.06.2015 18:00"
}
但就我所知,我无法按分析字段中的值进行排序。在这里,我尝试创建一个映射:

 { 
      "mappings": { 
        "_default_": { 
          "dynamic_templates": [ 
            { 
              "base": { 
                "match": "*", 
                "mapping": { 
                  "type": "multi_field", 
                  "fields": { 
                    "{name}": {"type": "string"}, 
                    "_sort": {"type": "string", "analyzer": "sort"} 
                  } 
                } 
              } 
            } 
          ] 
        } 
      }, 
      "settings": { 
        "analysis": { 
          "analyzer": { 
            "sort": { 
              "type": "custom", 
              "tokenizer": "keyword", 
              "filter": "lowercase" 
            } 
          } 
        } 
      } 
    } 
但如果我放置此配置,我将得到一个异常:ElasticsearchIllegalArgumentException:unknown属性。如果没有这种映射,我的索引就可以正常工作

我想做的是创建一个名为name_sort not_analysis的多字段,以便可以按值排序

**** 
At leas I can able to create a mapping correctly. My mapping looks like: 

 {
  "muhamo": {
    "mappings": {
      "bookings": {
        "dynamic_templates": [
          {
            "base": {
              "mapping": {
                "index": "analyzed",
                "type": "{dynamic_type}",
                "fields": {
                  "{name}_sort": {
                    "index": "not_analyzed",
                    "type": "{dynamic_type}"
                  }
                }
              },
              "match": "*",
              "match_mapping_type": "string"
            }
          },
          {
            "catch_all": {
              "mapping": {
                "fields": {
                  "{name}_sort": {
                    "index": "not_analyzed",
                    "type": "{dynamic_type}"
                  }
                }
              },
              "match": "*",
              "match_mapping_type": "*"
            }
          }
        ],
        "properties": {
          "bookingType": {
            "type": "string",
            "fields": {
              "bookingType_sort": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "comment": {
            "type": "string",
            "fields": {
              "comment_sort": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "costLocation": {
            "type": "string",
            "fields": {
              "costLocation_sort": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "customer": {
            "properties": {
              "fullname": {
                "type": "string",
                "fields": {
                  "fullname_sort": {
                    "type": "string",
                    "index": "not_analyzed"
                  }
                }
              }
            }
          },
          "date": {
            "type": "string",
            "fields": {
              "date_sort": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "deleted": {
            "type": "boolean"
          },
          "toAirport": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
但是,如果我尝试按customer.fullname\u排序对结果进行排序,我会得到一个例外

 query[ConstantScore(*:*)],from[-1],size[-1]: Parse Failure [No mapping found for [customer.fullname_sort] in order to sort on]
您应该按customer.fullname.fullname\u排序。根据索引的映射,这是字段的路径