타입을 정할수있다. 

 

 

 

 

String 6.x부터는 text로변경되었다. 

 

{ 

"class" : { 

"properties" : { 

"title" : {"type" : "text"}, 

"professor" : { "type" : "text"}, 

"major" : {"type" : "text"}, 

"semester" : {"type" : "text" }, 

"student_count" : {"type" : "integer"}, 

"unit" : {"type" : "integer"}, 

"submit_date" : {"type" : "date","format" : "yyyy-MM-dd"}, 

"school_location" : {"type" : "geo_point"} 

} 

} 

} 

 

{ 

  "classes" : { 

    "aliases" : { }, 

    "mappings" : { 

      "class" : { 

        "properties" : { 

          "major" : { 

            "type" : "text" 

          }, 

          "professor" : { 

            "type" : "text" 

          }, 

          "school_location" : { 

            "type" : "geo_point" 

          }, 

          "semester" : { 

            "type" : "text" 

          }, 

          "student_count" : { 

            "type" : "integer" 

          }, 

          "submit_date" : { 

            "type" : "date", 

            "format" : "yyyy-MM-dd" 

          }, 

          "title" : { 

            "type" : "text" 

          }, 

          "unit" : { 

            "type" : "integer" 

          } 

        } 

      } 

    }, 

    "settings" : { 

      "index" : { 

        "creation_date" : "1519968181208", 

        "number_of_shards" : "5", 

        "number_of_replicas" : "1", 

        "uuid" : "bc-lXSbRTdO88MARZ8qvDQ", 

        "version" : { 

          "created" : "6020299" 

        }, 

        "provided_name" : "classes" 

      } 

    } 

  } 

} 

 

그후에 데이터를 넣어보면 

요렇게 나온다 

 

 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 1, 

  "found" : true, 

  "_source" : { 

    "title" : "Machine Learning", 

    "Professor" : "Minsuk Heo", 

    "major" : "Computer Science", 

    "semester" : [ 

      "spring", 

      "fall" 

    ], 

    "student_count" : 100, 

    "unit" : 3, 

    "rating" : 5, 

    "submit_date" : "2016-01-02", 

    "school_location" : { 

      "lat" : 36.0, 

      "lon" : -120.0 

    } 

  } 

} 

 

 

 

 


'오락기 > ELK' 카테고리의 다른 글

elasticsearch aggregation  (0) 2018.05.11
elasticsearch search  (0) 2018.05.11
elasticsearch bulk  (0) 2018.05.11
elasticsearch update  (0) 2018.05.11
elasticsearch put / delete / post  (0) 2018.05.11

 

Update  

 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 1, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John" 

  } 

} 

[js@localhost elasticsearch]$ curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type:application/json' -d'{"doc" : {"unit" : 1} }' 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 2, 

  "result" : "updated", 

  "_shards" : { 

    "total" : 2, 

    "successful" : 1, 

    "failed" : 0 

  }, 

  "_seq_no" : 3, 

  "_primary_term" : 1 

} 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 2, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John", 

    "unit" : 1 

  } 

} 

 

Unit 필드가 늘어남 

 

Unit 수정해봄 

[js@localhost elasticsearch]$ curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type:application/json' -d'{"doc" : {"unit" : 2} }' 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 3, 

  "result" : "updated", 

  "_shards" : { 

    "total" : 2, 

    "successful" : 1, 

    "failed" : 0 

  }, 

  "_seq_no" : 4, 

  "_primary_term" : 1 

} 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 3, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John", 

    "unit" : 2 

  } 

} 

[js@localhost elasticsea 
 

스크립트도 가능 

Source.unit += 5 

 

[js@localhost elasticsearch]$ curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type:application/json' -d'{"script" : "ctx._source.unit +=5"}' 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 4, 

  "result" : "updated", 

  "_shards" : { 

    "total" : 2, 

    "successful" : 1, 

    "failed" : 0 

  }, 

  "_seq_no" : 5, 

  "_primary_term" : 1 

} 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 4, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John", 

    "unit" : 7 

  } 

} 

[js@localhost elasticsearch]$ 

 

 


'오락기 > ELK' 카테고리의 다른 글

elasticsearch aggregation  (0) 2018.05.11
elasticsearch search  (0) 2018.05.11
elasticsearch mapping  (0) 2018.05.11
elasticsearch update  (0) 2018.05.11
elasticsearch put / delete / post  (0) 2018.05.11

 

Update  

 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 1, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John" 

  } 

} 

[js@localhost elasticsearch]$ curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type:application/json' -d'{"doc" : {"unit" : 1} }' 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 2, 

  "result" : "updated", 

  "_shards" : { 

    "total" : 2, 

    "successful" : 1, 

    "failed" : 0 

  }, 

  "_seq_no" : 3, 

  "_primary_term" : 1 

} 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 2, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John", 

    "unit" : 1 

  } 

} 

 

Unit 필드가 늘어남 

 

Unit 수정해봄 

[js@localhost elasticsearch]$ curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type:application/json' -d'{"doc" : {"unit" : 2} }' 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 3, 

  "result" : "updated", 

  "_shards" : { 

    "total" : 2, 

    "successful" : 1, 

    "failed" : 0 

  }, 

  "_seq_no" : 4, 

  "_primary_term" : 1 

} 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 3, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John", 

    "unit" : 2 

  } 

} 

[js@localhost elasticsea 
 

스크립트도 가능 

Source.unit += 5 

 

[js@localhost elasticsearch]$ curl -XPOST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-Type:application/json' -d'{"script" : "ctx._source.unit +=5"}' 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 4, 

  "result" : "updated", 

  "_shards" : { 

    "total" : 2, 

    "successful" : 1, 

    "failed" : 0 

  }, 

  "_seq_no" : 5, 

  "_primary_term" : 1 

} 

[js@localhost elasticsearch]$ curl -XGET http://localhost:9200/classes/class/1/?pretty 

{ 

  "_index" : "classes", 

  "_type" : "class", 

  "_id" : "1", 

  "_version" : 4, 

  "found" : true, 

  "_source" : { 

    "title" : "Algorithm", 

    "professor" : "John", 

    "unit" : 7 

  } 

} 

[js@localhost elasticsearch]$ 

 

 


'오락기 > ELK' 카테고리의 다른 글

elasticsearch aggregation  (0) 2018.05.11
elasticsearch search  (0) 2018.05.11
elasticsearch mapping  (0) 2018.05.11
elasticsearch bulk  (0) 2018.05.11
elasticsearch put / delete / post  (0) 2018.05.11

INDEX 

GET 

 

 

 

PUT 

 

 

 

DELETE 

 

 

 

 

 

DOCUMENT  

 

POST -> INDEX 없어도 타입과 값을 명시하면 INDEX PUT하지않아도 생성가능 

 

> {"title":"Algorithm","professor":"John"}' 

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406} 

 

에러가 떠러짐  

 

보니 content - type  정해지지않아서 그런거같다. 6.0이전에는 가능했는데  이후로는 안된단다. 

 

그래서 타입을 정해주고 해보자 

 

 

 

 

Json 파일을 이용한 POST 

curl -XPOST http://localhost:9200/test/1/ -H 'Content-Type:application/json' -d @test.json 

 


'오락기 > ELK' 카테고리의 다른 글

elasticsearch aggregation  (0) 2018.05.11
elasticsearch search  (0) 2018.05.11
elasticsearch mapping  (0) 2018.05.11
elasticsearch bulk  (0) 2018.05.11
elasticsearch update  (0) 2018.05.11

https://www.acmicpc.net/problem/2675


S를 입력받운후에 R번 반복해 T를 출력


첫번째 줄은 줄수


첫번째 엘리먼트 첫번째껀 횟수 두번째껀 반복해야할 문자열


.input

2
3 ABC
5 /HTP

out

AAABBBCCC
/////HHHHHTTTTTPPPPP


code



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        
        //97~122  아스키 a-z
        
        Scanner sc = new Scanner(System.in);
        String count = sc.nextLine().trim();
        String[] input = new String[Integer.parseInt(count)];
        int copyCount = 0;
        String sum="";
        for(int i=0; i< (Integer.parseInt(count)) ; i++) {
            sum="";
            input[i] = sc.nextLine().trim();
            copyCount = Integer.parseInt(input[i].substring(0, 1));
            input[i] = input[i].substring(1, input[i].length()).trim();
            
            for(int j=0 ; j<input[i].length() ;j++) {
                
                for(int k=0; k<copyCount ;k++)    sum += input[i].charAt(j);
                
            }
            
            System.out.println(sum);
        }
        
    }
        
}
 


'오락기 > codeWar' 카테고리의 다른 글

백준 2908 상수  (0) 2018.05.25
백준 1157 단어공부  (0) 2018.05.25
백준 10809 알파벳찾기  (0) 2018.05.11
백준 11654  (0) 2018.05.11
백준 10039  (0) 2018.05.11

알파뱃 갯수를 순서대로

출력한다 없으면 0


baekjoon

out

1 0 -1 -1 2 -1 -1 -1 -1 4 3 -1 -1 7 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

a가 1번째

b가 0번째

이 순서


code


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        
        //97~122  아스키 a-z
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine().trim();
//        String input = "baekjoon";
        char[] output  = new char[26];
        int [] outInt = new int[26];
        char buff;
        int out=0;
        boolean tf = false;
        for(int i=0 ; ; i++) {
            out = i+97;
            output[i] =  (charout;
            outInt[i] = -1;
            if(output[i] == 'z'break;
        }
    
//        System.out.println(Arrays.toString(output));
        
        for(int i=0 ;i<output.length ; i++) {
            
            for(int j=0; j<input.length() ;j++) {
                buff = input.charAt(j);
                if(buff == output[i] && outInt[i] <= -1 ) {
                    outInt[i] = j;
                }
                
            }
        }
//        System.out.println(Arrays.toString(outInt));
        
        for(int i=0; i<outInt.length ; i++) {
            System.out.print(outInt[i]+" ");
        }
    }
        
}
 


'오락기 > codeWar' 카테고리의 다른 글

백준 1157 단어공부  (0) 2018.05.25
2675 백준 문자열반복  (0) 2018.05.11
백준 11654  (0) 2018.05.11
백준 10039  (0) 2018.05.11
백준 2920  (0) 2018.05.03

아스키 코드


알파벳 소문자 대문자 숫자 0-9중에 하나 주어졌을때 아스키 코드 출력


input

A

out

65

code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine().trim();
        
        System.out.println((int)input.charAt(0));
        
    }
        
}
 


'오락기 > codeWar' 카테고리의 다른 글

2675 백준 문자열반복  (0) 2018.05.11
백준 10809 알파벳찾기  (0) 2018.05.11
백준 10039  (0) 2018.05.11
백준 2920  (0) 2018.05.03
백준 2577  (0) 2018.04.25

평균점수 구하는


입력은 총 5줄

각가 점수의 평균

단 40점 미만은 무조건 40점으로 환산


input

10
65
100
30
95

out

68



code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package{
  public class {
    public static void main(String arg[]) {
      
    }
  }
}
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int[] input = new int[5];
        int buff=0;
        int sum=0;
        for(int i= 0 ; i<5 ; i++) {
            
            buff  =     Integer.parseInt(sc.nextLine().trim());
            
            if(buff < 40) buff =40;
            input[i] = buff;
            sum +=buff;
        }
        
//        System.out.println(Arrays.toString(input));
        System.out.println( sum/5);
        
 
        
        
    }
        
}
 


'오락기 > codeWar' 카테고리의 다른 글

백준 10809 알파벳찾기  (0) 2018.05.11
백준 11654  (0) 2018.05.11
백준 2920  (0) 2018.05.03
백준 2577  (0) 2018.04.25
백준 8958  (0) 2018.04.25

항상 백준은 입력방식때문에 코드가 들어가야함



1 2 3 4 5 6 7 8


8 7 6 5 4 3 2 1
8 1 7 2 6 3 5 4


이런식으로 숫자가 오름차슴 내림차순일때는

 

ascending desending 이라하고 이 두개가 아닐경우 mixed라고 출력한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=0;
        String[] input = new String[8];
        String str = sc.nextLine();
        
        str = str.trim();
        for(int i=0;  i<str.length() ; i++ ){
            if(!("".equals(str.substring(i, i+1).trim()) ||  str.substring(i, i+1).trim() == null) ){
                input[a] = str.substring(i, i+1);
                a++;
            }
        }
        a=0;
        for(int i=1; i<8 ; i++){
            
            a = Integer.parseInt(input[i]) - Integer.parseInt(input[i-1]); 
            
            if(a>1 || a< -1){
                break;
            }
            
        }
        if(a ==1){
            System.out.println("ascending");
        }else if( a== -1){
            System.out.println("descending");
        }else{
            System.out.println("mixed");
        }
    }
}
 

'오락기 > codeWar' 카테고리의 다른 글

백준 11654  (0) 2018.05.11
백준 10039  (0) 2018.05.11
백준 2577  (0) 2018.04.25
백준 8958  (0) 2018.04.25
백준4673  (0) 2017.12.29

a*b*c 해서

나온숫자를 0부터 9까지 횟수 카운팅


input

150
266
427


output

3
1
0
2
0
0
0
2
0
0


public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int[] arr;

int[] result = new int[10];

int str1 = sc.nextInt();

int str2 = sc.nextInt();

int str3 = sc.nextInt();

int sum = str1*str2*str3;

String sumToString = String.valueOf(sum);

arr = new int[sumToString.length()];

for(int i=0; i < sumToString.length() ; i++){

arr[i] = Integer.valueOf(sumToString.substring(i, i+1));

for(int j =0 ; j<10 ; j++){

if(j == arr[i]){

result[j]++;

}

}

}

for(int i=0 ; i<result.length ; i++) {

System.out.println(result[i]);

}

}

'오락기 > codeWar' 카테고리의 다른 글

백준 10039  (0) 2018.05.11
백준 2920  (0) 2018.05.03
백준 8958  (0) 2018.04.25
백준4673  (0) 2017.12.29
백준 설탕문제  (0) 2017.11.07

+ Recent posts